From 54e56145a716396d090cd379fcca4eae09e109a0 Mon Sep 17 00:00:00 2001 From: Bryan Herman Date: Mon, 12 Aug 2013 14:37:47 -0400 Subject: [PATCH] updated entropy test --- tests/test_entropy/results.py | 28 ++++++++++++++++++++++++++++ tests/test_entropy/results_true.dat | 13 +++++++++++++ tests/test_entropy/test_entropy.py | 10 +++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tests/test_entropy/results.py create mode 100644 tests/test_entropy/results_true.dat diff --git a/tests/test_entropy/results.py b/tests/test_entropy/results.py new file mode 100644 index 0000000000..d4fa17d4e1 --- /dev/null +++ b/tests/test_entropy/results.py @@ -0,0 +1,28 @@ +#!/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() + +# 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 += 'entropy:\n' +for item in sp.entropy: + 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_entropy/results_true.dat b/tests/test_entropy/results_true.dat new file mode 100644 index 0000000000..f650e44c47 --- /dev/null +++ b/tests/test_entropy/results_true.dat @@ -0,0 +1,13 @@ +k-combined: +0.30078030 0.00343315 +entropy: +6.42970620 +6.39285931 +6.64491815 +6.58470936 +6.53553278 +6.67552398 +6.69709001 +6.71408313 +6.55064371 +6.52434363 diff --git a/tests/test_entropy/test_entropy.py b/tests/test_entropy/test_entropy.py index 260af75774..2f43cbd3f6 100644 --- a/tests/test_entropy/test_entropy.py +++ b/tests/test_entropy/test_entropy.py @@ -2,6 +2,7 @@ import os from subprocess import Popen, STDOUT, PIPE +import filecmp pwd = os.path.dirname(__file__) @@ -18,8 +19,15 @@ def test_run(): def test_created_statepoint(): assert os.path.exists(pwd + '/statepoint.10.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 teardown(): - output = [pwd + '/statepoint.10.binary'] + output = [pwd + '/statepoint.10.binary', pwd + '/results_test.dat'] for f in output: if os.path.exists(f): os.remove(f)