def test_model_single(self): """Tests binary operations on SingleValuedWorkspace.""" for operation in self.operations: output_ws = "test_model_single_{}".format(operation) model = WorkspaceCalculatorModel(lhs_ws=self.single_value_lhs, rhs_ws=self.single_value_rhs, output_ws=output_ws, operation=operation) valid_lhs, valid_rhs, err_msg = model.performOperation() self.assertTrue(mtd[output_ws]) self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=True) if operation == "+": self.assertEqual(mtd[output_ws].readY(0)[0], 3) elif operation == "-": self.assertEqual(mtd[output_ws].readY(0)[0], -1) elif operation == "*": self.assertEqual(mtd[output_ws].readY(0)[0], 2) elif operation == "/": self.assertAlmostEqual(mtd[output_ws].readY(0)[0], 0.500, delta=0.001) elif operation == "WM": self.assertAlmostEqual(mtd[output_ws].readY(0)[0], 1.200, delta=0.001)
def test_model_validate_md_mixed(self): """Tests for validation of a group containing both Matrix and MDHisto workspaces.""" for operation in self.operations: output_ws = "test_model_validate_md_mixed_{}".format(operation) model = WorkspaceCalculatorModel() valid_lhs, valid_rhs, err_msg = model.validateInputs( lhs_ws=self.md_mixed_group) passed = False self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=passed) if passed: self.assertTrue(mtd[output_ws])
def test_model_md_groups(self): """Tests for binary operations with equal-size groups containing MDHisto workspaces.""" for operation in self.operations: output_ws = "test_model_md_groups_{}".format(operation) model = WorkspaceCalculatorModel(lhs_ws=self.md_group_lhs, rhs_ws=self.md_group_rhs, output_ws=output_ws, operation=operation) valid_lhs, valid_rhs, err_msg = model.performOperation() self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=True) self.assertTrue(mtd[output_ws])
def test_model_event(self): """Tests binary operations on EventWorkspaces.""" for operation in self.operations: output_ws = "test_model_event_{}".format(operation) model = WorkspaceCalculatorModel(lhs_ws=self.event_lhs, rhs_ws=self.event_rhs, output_ws=output_ws, operation=operation) valid_lhs, valid_rhs, err_msg = model.performOperation() self.assertTrue(mtd[output_ws]) self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=True)
def test_model_non_equal_matrix_groups(self): """Tests binary operations on non-equal size groups containing MatrixWorkspaces.""" for operation in self.operations: output_ws = "test_model_matrix_groups_{}".format(operation) model = WorkspaceCalculatorModel(lhs_ws=self.matrix_group_lhs, rhs_ws=self.matrix_group_larger, output_ws=output_ws, operation=operation) valid_lhs, valid_rhs, err_msg = model.performOperation() passed = False self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=passed)
def test_model_single_and_md_group(self): """Tests for binary operations between SingleValuedWorkspace and a group containing MDHisto workspaces.""" for operation in self.operations: output_ws = "test_model_single_and_md_{}".format(operation) model = WorkspaceCalculatorModel(lhs_ws=self.md_group_lhs, rhs_ws=self.single_value_rhs, output_ws=output_ws, operation=operation) valid_lhs, valid_rhs, err_msg = model.performOperation() passed = True if operation == 'WM': passed = False self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=passed) if passed: self.assertTrue(mtd[output_ws])
def test_model_matrix_scaling(self): """Tests binary operations on MatrixWorkspaces with scaling by arbitrary floats.""" lhs_scaling = 10.12452 rhs_scaling = -1e2 output_ws = 'test_model_matrix_scaling' model = WorkspaceCalculatorModel(lhs_scale=lhs_scaling, lhs_ws=self.matrix_lhs, rhs_scale=rhs_scaling, rhs_ws=self.matrix_rhs, output_ws=output_ws, operation='+') valid_lhs, valid_rhs, err_msg = model.performOperation() self.assertTrue(mtd[output_ws]) self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=True) value = mtd[output_ws].readY(0)[0] self.assertAlmostEqual(value, -26.9626, delta=1e-4)
def test_model_single_scaling(self): """Tests SingleValuedWorkspace scaling by arbitrary float parameters.""" lhs_scaling = -1.2452 rhs_scaling = 1e-5 output_ws = 'test_model_single_scaling' model = WorkspaceCalculatorModel(lhs_scale=lhs_scaling, lhs_ws=self.single_value_lhs, rhs_scale=rhs_scaling, rhs_ws=self.single_value_rhs, output_ws=output_ws, operation='+') valid_lhs, valid_rhs, err_msg = model.performOperation() self.assertTrue(mtd[output_ws]) self.check_validity(lhs_validation=valid_lhs, rhs_validation=valid_rhs, err_msg=err_msg, passed=True) value = mtd[output_ws].readY(0)[0] self.assertAlmostEqual(value, -1.24518, delta=1e-5)
def test_default_model(self): """Tests the default model and whether the correct validity flags are set.""" model = WorkspaceCalculatorModel() valid_lhs, valid_rhs, _, = model.performOperation() self.assertEqual(valid_lhs, False) self.assertEqual(valid_rhs, False)