Beispiel #1
0
 def test_compare_recursive(self):
     n = 20
     seq_a = [ordinal([(1, 1)])]
     seq_b = [ordinal([(1, 1), (0, 1)])]
     while len(seq_a) < n:
         seq_a.append(ordinal([(seq_a[-1], 2), (2, 1)]))
         seq_b.append(ordinal([(seq_b[-1], 1)]))
     for i in range(n):
         a = seq_a[i]
         b = seq_b[i]
         self.assertTrue(a < b)
         self.assertTrue(a <= b)
         self.assertTrue(a != b)
         self.assertFalse(a > b)
         self.assertFalse(a >= b)
         self.assertFalse(a == b)
     for i in range(1, n):
         b = seq_a[i]
         for j in range(i):
             a = seq_a[j]
             self.assertTrue(a < b)
             self.assertTrue(a <= b)
             self.assertTrue(a != b)
             self.assertFalse(a > b)
             self.assertFalse(a >= b)
             self.assertFalse(a == b)
         b = seq_b[i]
         for j in range(i):
             a = seq_b[j]
             self.assertTrue(a < b)
             self.assertTrue(a <= b)
             self.assertTrue(a != b)
             self.assertFalse(a > b)
             self.assertFalse(a >= b)
             self.assertFalse(a == b)
Beispiel #2
0
    def test_constants(self):
        """
        Small test case to ensure all the provided constants,
        such as omega, are actually the ordinals they're supposed to be.
        """
        from ordinal import ordinal, omega, epsilon_0, zeta_0

        self.assertEqual(omega, ordinal('omega'))
        self.assertEqual(epsilon_0, ordinal('epsilon_0'))
        self.assertEqual(zeta_0, ordinal('zeta_0'))

        self.assertTrue(1 < omega)
        self.assertTrue(omega < epsilon_0)
        self.assertTrue(epsilon_0 < zeta_0)
Beispiel #3
0
def seasons(i):
    """Seasons as strings for searching"""
    i = int(i)
    if i == 0:
        return 'Specials'
    else:
        return ordinal(i)
Beispiel #4
0
 def test_add_large(self):
     small = 2**8191 - 1
     big = ordinal([(2, 1), (1, 2)])
     huge = ordinal([(big, 3)])
     operands = [
         ordinal([(small, 7), (0, 2)]),
         ordinal([(big, 2), (0, 5)]),
         ordinal([(huge, 1), (small, 8), (0, 3)]),
         ordinal([(huge, 4), (big, 3), (0, 6)])
     ]
     results = [[(small, 14), (0, 2)], [(big, 2), (0, 5)],
                [(huge, 1), (small, 8), (0, 3)],
                [(huge, 4), (big, 3), (0, 6)], [(big, 2), (small, 7),
                                                (0, 2)], [(big, 4), (0, 5)],
                [(huge, 1), (small, 8), (0, 3)],
                [(huge, 4), (big, 3), (0, 6)],
                [(huge, 1), (small, 15), (0, 2)],
                [(huge, 1), (big, 2), (0, 5)],
                [(huge, 2), (small, 8), (0, 3)],
                [(huge, 5), (big, 3), (0, 6)],
                [(huge, 4), (big, 3), (small, 7), (0, 2)],
                [(huge, 4), (big, 5), (0, 5)],
                [(huge, 5), (small, 8), (0, 3)],
                [(huge, 8), (big, 3), (0, 6)]]
     for (a, b), r in zip(itertools.product(*[operands] * 2), results):
         self.assertEqual(r, ordinal(a + b).cnf)
Beispiel #5
0
def mainMenu(scaleLetter, num, reps):
    if len(sys.argv) < 3:
        scaleLetter = input(
            "Please enter a scale. eg: g# or ab or a: ").title()
        num = float(input("Please enter flash interval: "))
        reps = int(
            input("Please enter number of reps or press enter to continue: "))
        degrees = int(input("Please enter number of keys to use: "))
        reps = 99 if reps == 0 else reps

    for lvl in range(degrees, 8):
        if lvl == 5:
            reps = 49
        # selected scale to practice
        scale = scales[scaleLetter]
        if os.name == "posix":
            os.system("clear")
        else:
            os.system("cls")
        print(f"Flashing keys in the {scaleLetter} scale")
        print(f"    Interval: {num}s")
        print(f"    Reps: {reps}")
        print(f"    Degree: {lvl}")
        print("    Notes: " + ", ".join(scale[0:8]))
        print("===================")
        print()
        print()

        print('        Position:  Key')
        for r in range(1, lvl + 1):
            print('   {} tone of {}:  {}'.format(ordinal(r), scaleLetter,
                                                 scale[r - 1]))
        input("Press enter to continue... ")
        print()
        print()
        for i in range(reps):
            r = randint(1, lvl)
            print('   {} tone of {}:  '.format(ordinal(r), scaleLetter),
                  end=' ',
                  flush=True)
            sleep(num)
            print(scale[r - 1])
            sleep(1)
    mainMenu(scaleLetter, num, reps)
Beispiel #6
0
def seasons(i):
    """Seasons as strings for searching"""
    try:
        i = int(i)
    except:
        i = 0
    if i == 0:
        return 'Specials'
    else:
        return ordinal(i)
Beispiel #7
0
 def test_multiply_basic(self):
     operands = [
         ordinal([]),  # 0
         ordinal([(0, 1)]),  # 1
         ordinal([(0, 4)]),  # 4
         ordinal([(1, 1)]),  # omega
         ordinal([(2, 9)]),  # omega**2 * 9
     ]
     results = [[], [], [], [], [], [], [(0, 1)], [(0, 4)], [(1, 1)],
                [(2, 9)], [], [(0, 4)], [(0, 16)], [(1, 1)], [(2, 9)], [],
                [(1, 1)], [(1, 4)], [(2, 1)], [(3, 9)], [], [(2, 9)],
                [(2, 36)], [(3, 1)], [(4, 9)]]
     for (a, b), r in zip(itertools.product(*[operands] * 2), results):
         self.assertEqual(r, ordinal(a * b).cnf)
Beispiel #8
0
 def test_add_basic(self):
     operands = [
         ordinal([]),  # 0
         ordinal([(0, 1)]),  # 1
         ordinal([(0, 4)]),  # 4
         ordinal([(1, 1)]),  # omega
         ordinal([(2, 9)]),  # omega**2 * 9
     ]
     results = [[], [(0, 1)], [(0, 4)], [(1, 1)], [(2, 9)], [(0, 1)],
                [(0, 2)], [(0, 5)], [(1, 1)], [(2, 9)], [(0, 4)], [(0, 5)],
                [(0, 8)], [(1, 1)], [(2, 9)], [(1, 1)], [(1, 1), (0, 1)],
                [(1, 1), (0, 4)], [(1, 2)], [(2, 9)], [(2, 9)],
                [(2, 9), (0, 1)], [(2, 9), (0, 4)], [(2, 9), (1, 1)],
                [(2, 18)]]
     for (a, b), r in zip(itertools.product(*[operands] * 2), results):
         self.assertEqual(r, ordinal(a + b).cnf)
	def test_string(self):
		self.assertEqual("Enter a number!", ordinal.ordinal('b'))
 def test_third(self):
   self.assertEqual("3rd", ordinal.ordinal(3))
	def test_st(self):
		self.assertEqual('21st',ordinal.ordinal(21))
 def test_eleventh(self):
 	self.assertEqual("11th", ordinal.ordinal(11))
Beispiel #13
0
 def test_instance_warn(self):
     warnings.simplefilter('error')
     with self.assertRaises(UserWarning):
         ordinal(-1)
     with self.assertRaises(UserWarning):
         ordinal([], unchecked=True)
     with self.assertRaises(UserWarning):
         ordinal([(1 / 2, 1)], unchecked=True)
     with self.assertRaises(UserWarning):
         ordinal([(-1, 1)], unchecked=True)
     with self.assertRaises(UserWarning):
         ordinal([(1, 1 / 2)], unchecked=True)
     with self.assertRaises(UserWarning):
         ordinal([(1, -1)], unchecked=True)
     warnings.resetwarnings()
 def test_string(self):
     self.assertEqual("Enter a number!", ordinal.ordinal('b'))
 def test_third(self):
 	self.assertEqual("3rd", ordinal.ordinal(3))
 def test_decimal(self):
   self.assertEqual("1st", ordinal.ordinal(1.0))
 def test_string_input(self):
   self.assertEqual("1st", ordinal.ordinal("1"))
   self.assertEqual("Improper input", ordinal.ordinal("abc"))
 def test_one_thousand_two(self):
   self.assertEqual("1002nd", ordinal.ordinal(1002))
 def test_negative_one(self):
   self.assertEqual("-1st", ordinal.ordinal(-1))
 def test_twelfth(self):
   self.assertEqual("12th", ordinal.ordinal(12))
 def test_eleventh(self):
   self.assertEqual("11th", ordinal.ordinal(11))
 def test_fourth(self):
   self.assertEqual("4th", ordinal.ordinal(4))
Beispiel #23
0
 def test_negative_one(self):
  self.assertEqual("-1st", ordinal.ordinal(-1))
 def test_zero(self):
   self.assertEqual("0th", ordinal.ordinal(0))
Beispiel #25
0
    def test_integers(self):
        """
        Sanity tests involving ordinals that are mathematically
        integers and the builtin int objects.
        Since integers are very straightforward and cheap to
        test with, we do a lot of the low level sanity checks here.
        """
        from ordinal import ordinal, ordinal_type

        for i in range(100):

            self.assertTrue(isinstance(i, ordinal_type))
            self.assertTrue(isinstance(ordinal(i), ordinal_type))

            self.assertEqual(i == i, ordinal(i) == i)
            self.assertEqual(i == i, ordinal(i) == ordinal(i))
            self.assertEqual(i != i, ordinal(i) != i)
            self.assertEqual(i != i, ordinal(i) != ordinal(i))
            self.assertEqual(i > i, ordinal(i) > i)
            self.assertEqual(i > i, ordinal(i) > ordinal(i))
            self.assertEqual(i >= i, ordinal(i) >= i)
            self.assertEqual(i >= i, ordinal(i) >= ordinal(i))
            self.assertEqual(i < i, ordinal(i) < i)
            self.assertEqual(i < i, ordinal(i) < ordinal(i))
            self.assertEqual(i <= i, ordinal(i) <= i)
            self.assertEqual(i <= i, ordinal(i) <= ordinal(i))

        for j in range(1, 100):
            for i in range(j):

                self.assertEqual(i == j, ordinal(i) == j)
                self.assertEqual(i == j, ordinal(i) == ordinal(j))
                self.assertEqual(i != j, ordinal(i) != j)
                self.assertEqual(i != j, ordinal(i) != ordinal(j))
                self.assertEqual(i > j, ordinal(i) > j)
                self.assertEqual(i > j, ordinal(i) > ordinal(j))
                self.assertEqual(i >= j, ordinal(i) >= j)
                self.assertEqual(i >= j, ordinal(i) >= ordinal(j))
                self.assertEqual(i < j, ordinal(i) < j)
                self.assertEqual(i < j, ordinal(i) < ordinal(j))
                self.assertEqual(i <= j, ordinal(i) <= j)
                self.assertEqual(i <= j, ordinal(i) <= ordinal(j))

                self.assertEqual(j == i, ordinal(j) == i)
                self.assertEqual(j == i, ordinal(j) == ordinal(i))
                self.assertEqual(j != i, ordinal(j) != i)
                self.assertEqual(j != i, ordinal(j) != ordinal(i))
                self.assertEqual(j > i, ordinal(j) > i)
                self.assertEqual(j > i, ordinal(j) > ordinal(i))
                self.assertEqual(j >= i, ordinal(j) >= i)
                self.assertEqual(j >= i, ordinal(j) >= ordinal(i))
                self.assertEqual(j < i, ordinal(j) < i)
                self.assertEqual(j < i, ordinal(j) < ordinal(i))
                self.assertEqual(j <= i, ordinal(j) <= i)
                self.assertEqual(j <= i, ordinal(j) <= ordinal(i))

        with self.assertRaises(ValueError):
            ordinal(-1)

        with self.assertRaises(TypeError):
            ordinal(0.5)
 def test_first(self):
   self.assertEqual("1st", ordinal.ordinal(1))
 def test_st(self):
     self.assertEqual('21st', ordinal.ordinal(21))
Beispiel #28
0
 def test_multiply_mid(self):
     operands = [
         ordinal([(6, 8), (5, 7), (3, 6), (0, 5)]),
         ordinal([(ordinal([(1, 1), (0, 2)]), 3), (0, 4)]),
         ordinal([(ordinal([(1, 1), (0, 4)]), 3), (0, 2)])
     ]
     results = [[(12, 8), (11, 7), (9, 6), (6, 40)],
                [(ordinal([(1, 1), (0, 2)]), 3), (6, 32)],
                [(ordinal([(1, 1), (0, 4)]), 3), (6, 16)],
                [(ordinal([(1, 1), (0, 8)]), 8),
                 (ordinal([(1, 1), (0, 7)]), 7),
                 (ordinal([(1, 1), (0, 5)]), 6),
                 (ordinal([(1, 1), (0, 2)]), 15)],
                [(ordinal([(1, 2), (0, 2)]), 3),
                 (ordinal([(1, 1), (0, 2)]), 12)],
                [(ordinal([(1, 2), (0, 4)]), 3),
                 (ordinal([(1, 1), (0, 2)]), 6)],
                [(ordinal([(1, 1), (0, 10)]), 8),
                 (ordinal([(1, 1), (0, 9)]), 7),
                 (ordinal([(1, 1), (0, 7)]), 6),
                 (ordinal([(1, 1), (0, 4)]), 15)],
                [(ordinal([(1, 2), (0, 2)]), 3),
                 (ordinal([(1, 1), (0, 4)]), 12)],
                [(ordinal([(1, 2), (0, 4)]), 3),
                 (ordinal([(1, 1), (0, 4)]), 6)]]
     for (a, b), r in zip(itertools.product(*[operands] * 2), results):
         self.assertEqual(r, ordinal(a * b).cnf)
 def test_forth(self):
 	self.assertEqual("4th", ordinal.ordinal(4))
Beispiel #30
0
 def test_instance_eq(self):
     self.assertEqual(ordinal(0), 0)
     self.assertEqual(ordinal(1), 1)
     self.assertEqual(ordinal(3), ordinal(3))
     self.assertEqual(ordinal('omega'), omega)
     self.assertEqual(ordinal(omega), omega)
 def test_first(self):
   self.assertEqual("1st", ordinal.ordinal(1)) # first ordinal is document from importing
	def test_nd(self):
		self.assertEqual('2nd',ordinal.ordinal(2))
	def test_first(self):
		self.assertEqual("1st", ordinal.ordinal(1))
 def test_second(self):
   self.assertEqual("2nd", ordinal.ordinal(2))
	def test_third(self):
		self.assertEqual(ordinal.ordinal(3), "3rd")
	def test_eleven(self):
		self.assertNotEqual(ordinal.ordinal(111), "111st")
Beispiel #37
0
 def test_instance_cnf(self):
     self.assertEqual(ordinal(0).cnf, [])
     self.assertEqual(ordinal(1).cnf, [(0, 1)])
     self.assertEqual(ordinal(7).cnf, [(0, 7)])
     self.assertEqual(ordinal('omega').cnf, [(1, 1)])
     self.assertEqual(ordinal([(4, 3), (2, 1)]).cnf, [(4, 3), (2, 1)])
	def test_other(self):
		self.assertEqual(ordinal.ordinal(34), "34th")		
Beispiel #39
0
 def test_compare(self):
     self.assertTrue(ordinal(omega) == omega)
     self.assertTrue(ordinal(omega) >= omega)
     self.assertTrue(ordinal(omega) <= omega)
     self.assertFalse(ordinal(omega) != omega)
     self.assertFalse(ordinal(omega) > omega)
     self.assertFalse(ordinal(omega) < omega)
     self.assertTrue(ordinal(0) == 0)
     self.assertTrue(ordinal(0) < 1)
     self.assertFalse(ordinal(1) < 0)
     self.assertFalse(ordinal(omega) < 0)
     self.assertTrue(ordinal(omega) > 1)
     ord_ref = ordinal([(3, 2), (1, 4), (0, 1)])
     for cnf in [[(1, 4), (0, 1)], [(1, 9)], [(3, 1), (1, 8)],
                 [(3, 1), (2, 6), (1, 7), (0, 8)], [(3, 2), (1, 3), (0, 7)],
                 [(3, 2), (1, 4)]]:
         ord_cmp = ordinal(cnf)
         self.assertTrue(ord_ref > ord_cmp)
         self.assertTrue(ord_ref >= ord_cmp)
         self.assertTrue(ord_ref != ord_cmp)
         self.assertFalse(ord_ref < ord_cmp)
         self.assertFalse(ord_ref <= ord_cmp)
         self.assertFalse(ord_ref == ord_cmp)
     for cnf in [[(3, 2), (1, 4), (0, 1)]]:
         ord_cmp = ordinal(cnf)
         self.assertTrue(ord_ref == ord_cmp)
         self.assertTrue(ord_ref >= ord_cmp)
         self.assertTrue(ord_ref <= ord_cmp)
         self.assertFalse(ord_ref < ord_cmp)
         self.assertFalse(ord_ref > ord_cmp)
         self.assertFalse(ord_ref != ord_cmp)
     for cnf in [[(3, 2), (1, 4), (0, 2)], [(3, 2), (1, 5)], [(3, 2),
                                                              (2, 1)],
                 [(3, 3), (0, 1)], [(4, 1)]]:
         ord_cmp = ordinal(cnf)
         self.assertTrue(ord_ref < ord_cmp)
         self.assertTrue(ord_ref <= ord_cmp)
         self.assertTrue(ord_ref != ord_cmp)
         self.assertFalse(ord_ref > ord_cmp)
         self.assertFalse(ord_ref >= ord_cmp)
         self.assertFalse(ord_ref == ord_cmp)
Beispiel #40
0
 def test_second(self):
  self.assertEqual("2nd", ordinal.ordinal(2))
Beispiel #41
0
 def ordinal(self, number):
     return ordinal.ordinal(number)
Beispiel #42
0
 def test_second(self):
  self.assertEqual("11th", ordinal.ordinal(11))
	def test_first(self):
		self.assertEqual(ordinal.ordinal(self.value), "1st")
	def test_eleven(self):
		self.assertEqual('11th',ordinal.ordinal(11))
Beispiel #45
0
 def test_second(self):
  self.assertEqual("3rd", ordinal.ordinal(3))
	def test_second(self):
		self.assertEqual(ordinal.ordinal(2), "2nd")
Beispiel #47
0
 def test_string_input(self):
  self.assertEqual("Input is not a number.", ordinal.ordinal("1"))
 def test_nd(self):
     self.assertEqual('2nd', ordinal.ordinal(2))
Beispiel #49
0
 def test_first(self):
  self.assertEqual("1st", ordinal.ordinal(1)) # first ordinal: module, second ordinal: method
 def test_eleven(self):
     self.assertEqual('11th', ordinal.ordinal(11))