From 5627bb8cd6ba26386d1fa459e687db9243e605f2 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 15:39:07 -0400 Subject: [PATCH] updated particle_restart test --- tests/test_particle_restart/results.py | 33 +++++++++++++++++++ tests/test_particle_restart/results_true.dat | 14 ++++++++ .../test_particle_restart.py | 10 +++++- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/test_particle_restart/results.py create mode 100644 tests/test_particle_restart/results_true.dat diff --git a/tests/test_particle_restart/results.py b/tests/test_particle_restart/results.py new file mode 100644 index 0000000000..a4a5831649 --- /dev/null +++ b/tests/test_particle_restart/results.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import sys + +# import particle restart +sys.path.append('../../src/utils') +import particle_restart as pr + +# read in particle restart file +p = pr.Particle('particle_10_638.binary') + +# set up output string +outstr = '' + +# write out properties +outstr += 'current batch:\n' +outstr += "{0:10.8f}\n".format(p.current_batch) +outstr += 'current gen:\n' +outstr += "{0:10.8f}\n".format(p.current_gen) +outstr += 'particle id:\n' +outstr += "{0:10.8f}\n".format(p.id) +outstr += 'particle weight:\n' +outstr += "{0:10.8f}\n".format(p.weight) +outstr += 'particle energy:\n' +outstr += "{0:10.8f}\n".format(p.energy) +outstr += 'particle xyz:\n' +outstr += "{0:10.8f} {1:10.8f} {2:10.8f}\n".format(p.xyz[0],p.xyz[1],p.xyz[2]) +outstr += 'particle uvw:\n' +outstr += "{0:10.8f} {1:10.8f} {2:10.8f}\n".format(p.uvw[0],p.uvw[1],p.uvw[2]) + +# write results to file +with open('results_test.dat','w') as fh: + fh.write(outstr) diff --git a/tests/test_particle_restart/results_true.dat b/tests/test_particle_restart/results_true.dat new file mode 100644 index 0000000000..6ba9253e3f --- /dev/null +++ b/tests/test_particle_restart/results_true.dat @@ -0,0 +1,14 @@ +current batch: +10.00000000 +current gen: +1.00000000 +particle id: +638.00000000 +particle weight: +1.00000000 +particle energy: +2.19644588 +particle xyz: +30.87637144 57.78785719 35.19837347 +particle uvw: +-0.69841548 -0.09803596 0.70894624 diff --git a/tests/test_particle_restart/test_particle_restart.py b/tests/test_particle_restart/test_particle_restart.py index b3a8b3396c..a4574b18ba 100644 --- a/tests/test_particle_restart/test_particle_restart.py +++ b/tests/test_particle_restart/test_particle_restart.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -17,6 +18,13 @@ def test_run(): def test_created_restart(): assert os.path.exists(pwd + '/particle_10_638.binary') +def test_results(): + os.system('python results.py') + compare = filecmp.cmp('results_test.dat', 'results_true.dat') + if not compare: + os.system('cp results_test.dat results_error.dat') + assert compare + def test_run_restart(): proc = Popen([pwd + '/../../src/openmc -s particle_10_638.binary'], stderr=PIPE, stdout=PIPE, shell=True) @@ -24,7 +32,7 @@ def test_run_restart(): assert stderr != '' def teardown(): - output = [pwd + '/particle_10_638.binary'] + output = [pwd + '/particle_10_638.binary', pwd + '/results_test.dat'] for f in output: if os.path.exists(f): os.remove(f)