From bd6269098ce68b7fd705ee27ccd0d0266f3a1cef Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 16:14:27 -0400 Subject: [PATCH] updated score_fission test --- tests/test_score_fission/results.py | 41 +++++++++++++++++++ tests/test_score_fission/results_true.dat | 20 +++++++++ .../test_score_fission/test_score_fission.py | 11 ++++- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 tests/test_score_fission/results.py create mode 100644 tests/test_score_fission/results_true.dat diff --git a/tests/test_score_fission/results.py b/tests/test_score_fission/results.py new file mode 100644 index 0000000000..d6ab485d95 --- /dev/null +++ b/tests/test_score_fission/results.py @@ -0,0 +1,41 @@ +#!/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 +results1 = sp.tallies[0].results +shape1 = results1.shape +size1 = (np.product(shape1)) +results1 = np.reshape(results1, size1) +results2 = sp.tallies[1].results +shape2 = results2.shape +size2 = (np.product(shape2)) +results2 = np.reshape(results2, size2) + +# set up output string +outstr = '' + +# write out k-combined +outstr += 'k-combined:\n' +outstr += "{0:10.8f} {1:10.8f}\n".format(sp.k_combined[0], sp.k_combined[1]) + +# write out tally results +outstr += 'tally 1:\n' +for item in results1: + outstr += "{0:10.8f}\n".format(item) +outstr += 'tally 2:\n' +for item in results2: + 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_score_fission/results_true.dat b/tests/test_score_fission/results_true.dat new file mode 100644 index 0000000000..fd39895f83 --- /dev/null +++ b/tests/test_score_fission/results_true.dat @@ -0,0 +1,20 @@ +k-combined: +1.63626998 0.13749537 +tally 1: +0.97781050 +0.19423327 +0.00000000 +0.00000000 +0.00000000 +0.00000000 +0.77289598 +0.12336152 +tally 2: +1.09000000 +0.23830000 +0.00000000 +0.00000000 +0.00000000 +0.00000000 +0.83000000 +0.14070000 diff --git a/tests/test_score_fission/test_score_fission.py b/tests/test_score_fission/test_score_fission.py index ca8daa9263..1cb3b704be 100644 --- a/tests/test_score_fission/test_score_fission.py +++ b/tests/test_score_fission/test_score_fission.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -21,8 +22,16 @@ def test_statepoint_exists(): 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', pwd + '/tallies.out'] + output = [pwd + '/statepoint.10.binary', pwd + '/tallies.out', + pwd + '/results_test.dat'] for f in output: if os.path.exists(f): os.remove(f)