HPS-MC
test_parameter_patterns.py
Go to the documentation of this file.
1 import unittest
2 import os
3 
4 from hpsmc.alignment._parameter import Parameter
5 from hpsmc.alignment._pattern import Pattern
6 
7 
8 class TestParameterPatterns(unittest.TestCase):
9 
11  param = Parameter.from_idn('11106')
12  self.assertEqual(Pattern(11106), param)
13  self.assertEqual(Pattern('11106'), param)
14  self.assertEqual(Pattern('id=11106'), param)
15 
16  def test_bad_patterns(self):
17  # ID number not matching pattern
18  with self.assertRaises(ValueError):
19  Pattern(52420)
20  with self.assertRaises(ValueError):
21  Pattern(1)
22  with self.assertRaises(ValueError):
23  Pattern('100123')
24 
25  # unary operation not listed
26  with self.assertRaises(ValueError):
27  Pattern('dne')
28  with self.assertRaises(ValueError):
29  Pattern('!dne')
30  with self.assertRaises(ValueError):
31  Pattern('top&dne')
32 
33  # binary operation bad format
34  with self.assertRaises(ValueError):
35  Pattern('id==11106')
36  with self.assertRaises(ValueError):
37  Pattern('dne=123')
38  with self.assertRaises(ValueError):
39  Pattern('half=dne')
40 
41  def test_match_unary(self):
42  individual = Pattern('individual')
43  self.assertEqual(individual, Parameter.from_idn(11106))
44  self.assertNotEqual(individual, Parameter.from_idn(12382))
45 
47  direction_u = Pattern('direction=u')
48  self.assertEqual(direction_u, Parameter.from_idn(11106))
49  self.assertNotEqual(direction_u, Parameter.from_idn(11206))
50 
52  operation_t = Pattern('translation')
53  self.assertEqual(operation_t, Parameter.from_idn(11106))
54  self.assertNotEqual(operation_t, Parameter.from_idn(12106))
55 
57  tu = Pattern('direction=u & translation')
58  self.assertEqual(tu, Parameter.from_idn(11106))
59  self.assertNotEqual(tu, Parameter.from_idn(12106))
60  self.assertNotEqual(tu, Parameter.from_idn(11206))
61 
63  stereo_tu = Pattern('stereo & direction=u & translation')
64  self.assertNotEqual(stereo_tu, Parameter.from_idn(11106))
65  self.assertNotEqual(stereo_tu, Parameter.from_idn(12106))
66  self.assertNotEqual(stereo_tu, Parameter.from_idn(11206))
67  self.assertEqual(stereo_tu, Parameter.from_idn(11107))
68 
69  def test_alias(self):
70  tu = Pattern('tu')
71  self.assertEqual(tu, Parameter.from_idn(11106))
72  self.assertNotEqual(tu, Parameter.from_idn(12106))
73  self.assertNotEqual(tu, Parameter.from_idn(11206))
74 
75  def test_combine_alias(self):
76  stereo_tu = Pattern('stereo & tu')
77  self.assertNotEqual(stereo_tu, Parameter.from_idn(11106))
78  self.assertNotEqual(stereo_tu, Parameter.from_idn(12106))
79  self.assertNotEqual(stereo_tu, Parameter.from_idn(11206))
80  self.assertEqual(stereo_tu, Parameter.from_idn(11107))
81 
82 
83 if __name__ == '__main__':
84  unittest.main()
Pattern that can match one or more paramters.
Definition: _pattern.py:6
representation of alignment parameters
Definition: _parameter.py:1
pattern that can match one or more Parameters
Definition: _pattern.py:1