From 0d26c6d8e1e16706ffc87ac3d0c9c12f8dc55a01 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 22 Dec 2022 17:42:30 +0100
Subject: [PATCH] test slicing more compact

---
 Tests/Py/Functional/PyFuTestInfrastructure.py | 15 ++++++++++++++-
 Tests/Py/Functional/slicing.py                | 10 ++--------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/Tests/Py/Functional/PyFuTestInfrastructure.py b/Tests/Py/Functional/PyFuTestInfrastructure.py
index 3ff7b7a14a2..3eb8226b533 100644
--- a/Tests/Py/Functional/PyFuTestInfrastructure.py
+++ b/Tests/Py/Functional/PyFuTestInfrastructure.py
@@ -5,9 +5,22 @@ Collection of utils for testing
 import bornagain as ba
 from bornagain import deg, angstrom
 
-# same as test::makeSimulation::MiniGISAS
+
 def get_simulation_MiniGISAS(sample):
     n = 25
     detector = ba.SphericalDetector(n, -2 * deg, 2 * deg, n, 0, 2 * deg)
     beam = ba.Beam(1., 1 * angstrom, ba.Direction(0.2 * deg, 0))
     return ba.ScatteringSimulation(beam, sample, detector)
+
+def diff_MiniGISAS(sample1, sample2):
+    """
+    Run standard GISAS simulation for two sample models, and return diff of results.
+    """
+    n = 11
+    detector = ba.SphericalDetector(n, 0, 5 * deg, n, 0, 4 * deg)
+    beam = ba.Beam(1., 1 * angstrom, ba.Direction(0.2 * deg, 0))
+
+    data1 = ba.ScatteringSimulation(beam, sample1, detector).simulate()
+    data2 = ba.ScatteringSimulation(beam, sample2, detector).simulate()
+
+    return ba.meanRelativeDifference(data1, data2)
diff --git a/Tests/Py/Functional/slicing.py b/Tests/Py/Functional/slicing.py
index 597f0e31616..d7771717927 100644
--- a/Tests/Py/Functional/slicing.py
+++ b/Tests/Py/Functional/slicing.py
@@ -42,18 +42,12 @@ class SlicedSpheresTest(unittest.TestCase):
 
         return sample
 
-    def get_result(self, particle, sliced):
-        sample = self.get_sample(particle, sliced)
-        simulation = infrastruct.get_simulation_MiniGISAS(sample)
-        return simulation.simulate()
-
     def testSlicingPyramid(self):
         ff = ba.Pyramid3(8., 10., 80*ba.deg)
         particle = ba.Particle(matSubstrate, ff)
-        dataA = self.get_result(particle, False)
-        dataB = self.get_result(particle, True)
 
-        diff = ba.meanRelativeDifference(dataA, dataB)
+        diff = infrastruct.diff_MiniGISAS(self.get_sample(particle, False),
+                                          self.get_sample(particle, True))
         self.assertLess(diff, 1e-13)
 
 
-- 
GitLab