From bfbc929e6682fdb4450b30a51dc08a9c604361ca Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 15:05:02 -0400 Subject: [PATCH] updated fixed_source test and added simple flux tally for comparison --- tests/test_fixed_source/results.py | 30 ++++++++++++++++++++ tests/test_fixed_source/results_true.dat | 3 ++ tests/test_fixed_source/tallies.xml | 8 ++++++ tests/test_fixed_source/test_fixed_source.py | 16 +++++++++-- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 tests/test_fixed_source/results.py create mode 100644 tests/test_fixed_source/results_true.dat create mode 100644 tests/test_fixed_source/tallies.xml diff --git a/tests/test_fixed_source/results.py b/tests/test_fixed_source/results.py new file mode 100644 index 0000000000..5f68ab742c --- /dev/null +++ b/tests/test_fixed_source/results.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +import sys +import numpy as np + +# import statepoint +sys.path.append('../../src/utils') +import statepoint + +# read in statepoint file +sp = statepoint.StatePoint('statepoint.10.binary') +sp.read_results() + +# extract tally results and convert to vector +results = sp.tallies[0].results +shape = results.shape +size = (np.product(shape)) +results = np.reshape(results, size) + +# set up output string +outstr = '' + +# write out tally results +outstr += 'tallies:\n' +for item in results: + outstr += "{0:10.8f}\n".format(item) + +# write results to file +with open('results_test.dat','w') as fh: + fh.write(outstr) diff --git a/tests/test_fixed_source/results_true.dat b/tests/test_fixed_source/results_true.dat new file mode 100644 index 0000000000..3f522c79a2 --- /dev/null +++ b/tests/test_fixed_source/results_true.dat @@ -0,0 +1,3 @@ +tallies: +471.58945263 +22414.09099170 diff --git a/tests/test_fixed_source/tallies.xml b/tests/test_fixed_source/tallies.xml new file mode 100644 index 0000000000..87e08d6c73 --- /dev/null +++ b/tests/test_fixed_source/tallies.xml @@ -0,0 +1,8 @@ + + + + + flux + + + diff --git a/tests/test_fixed_source/test_fixed_source.py b/tests/test_fixed_source/test_fixed_source.py index 260af75774..1cb3b704be 100644 --- a/tests/test_fixed_source/test_fixed_source.py +++ b/tests/test_fixed_source/test_fixed_source.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -15,11 +16,22 @@ def test_run(): print(proc.communicate()[0]) assert returncode == 0 -def test_created_statepoint(): +def test_statepoint_exists(): assert os.path.exists(pwd + '/statepoint.10.binary') +def test_output_exists(): + assert os.path.exists(pwd + '/tallies.out') + +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 teardown(): - output = [pwd + '/statepoint.10.binary'] + output = [pwd + '/statepoint.10.binary', pwd + '/tallies.out', + pwd + '/results_test.dat'] for f in output: if os.path.exists(f): os.remove(f)