Example #1
0
def test_solution():
    eq_('03/19/19', solution.answer(19, 19, 3))
    eq_('Ambiguous', solution.answer(3, 30, 3))
    eq_('Ambiguous', solution.answer(1, 1, 3))
    eq_('01/01/01', solution.answer(1, 1, 1))
    eq_('11/13/99', solution.answer(99, 11, 13))
    eq_('Ambiguous', solution.answer(12, 31, 30))
    eq_('02/28/29', solution.answer(2, 28, 29))
    eq_('Ambiguous', solution.answer(2, 12, 12))
Example #2
0
 def test_answer_neg_weights(self):
     times = [
         [0, 1, 1, 1, 1],  # 0 = Start
         [1, 0, 1, 1, 1],  # 1 = Bunny 0
         [1, 1, 0, 1, -1],  # 2 = Bunny 1
         [1, 1, 1, 0, 1],  # 3 = Bunny 2
         [1, 1, 1, 1, 0]  # 4 = Bulkhead
     ]
     time_limit = 2
     self.assertEqual(answer(times, time_limit), [0, 1])
Example #3
0
    def test_reference(self):
        a, b, c = ([1], [1, 1], [[1], 1, 1])
        list_ = [a, b, c]
        actual = answer(list_)
        self.assertEqual(actual, c)
        self.assertFalse(actual is c)

        deep = c[0]
        self.assertEqual(actual[0], deep)
        self.assertFalse(actual[0] is deep)
Example #4
0
def test_solution():
    eq_(solution.answer([1,4,2,5,1,2,3]), 5)
    eq_(solution.answer([1,2,3,2,1]), 0)
    eq_(solution.answer([2, 5, 1, 2, 3, 4, 7, 7, 6]), 10)
    eq_(solution.answer([2, 5, 1, 3, 1, 2, 1, 7, 7, 6]), 17)
    eq_(solution.answer([2, 7, 2, 7, 4, 7, 1, 7, 3, 7]), 18)
    eq_(solution.answer([6, 7, 7, 4, 3, 2, 1, 5, 2]), 10)
    eq_(solution.answer([2, 5, 1, 2, 3, 4, 7, 7, 6, 
                         2, 7, 1, 2, 3, 4, 5, 5, 4]), 26)
Example #5
0
 def test001(self):
     print 'test 002\n'
     population = [[6, 7, 2, 7, 6], [6, 3, 1, 4, 7], [0, 2, 4, 1, 10], [8, 1, 1, 4, 9], [8, 7, 4, 9, 9]]
     x = 2
     y = 1
     strength = 5
     r = solution.answer(population, x, y, strength)
     print '  input:\t', population, x, y, strength
     print '  expect:\t', [[6, 7, -1, 7, 6], [6, -1, -1, -1, 7], [-1, -1, -1, -1, 10], [8, -1, -1, -1, 9], [8, 7, -1, 9, 9]]
     print '  output:\t', r
     print
Example #6
0
 def test000(self):
     print 'test 000\n'
     population = [[1, 2, 3], [2, 3, 4], [3, 2, 1]]
     x = 0
     y = 0
     strength = 2
     r = solution.answer(population, x, y, strength)
     print '  input:\t', population, x, y, strength
     print '  expect:\t', [[-1, -1, 3], [-1, 3, 4], [3, 2, 1]]
     print '  output:\t', r
     print
Example #7
0
 def test_answer_with_cycles(self):
     times = [
         [0, 2, 2, 2, -1],  # 0 = Start
         [2, 0, 2, 2, -1],  # 1 = Bunny 0
         [2, 2, 0, 2, -1],  # 2 = Bunny 1
         [2, 2, 2, 0, -1],  # 3 = Bunny 2
         [2, 2, 2, 2, 0],  # 4 = Bulkhead
     ]
     # Sequential path distance = ??? = ???
     # Best path: ???; distance = 6
     time_limit = 1
     self.assertEqual(answer(times, time_limit), [0])
Example #8
0
 def test_answer_provided2(self):
     """
     This case is directed/asymmetrical with negative weights and negative-weighted cycles (I think), and cannot 
     rescue all bunnies within time limit.
     """
     times = [
         [0, 2, 2, 2, -1],  # 0 = Start
         [9, 0, 2, 2, -1],  # 1 = Bunny 0
         [9, 3, 0, 2, -1],  # 2 = Bunny 1
         [9, 3, 2, 0, -1],  # 3 = Bunny 2
         [9, 3, 2, 2, 0],  # 4 = Bulkhead
     ]
     time_limit = 1
     self.assertEqual(answer(times, time_limit), [1, 2])
Example #9
0
 def test_answer_max_dim_matrix(self):
     times = [
         [0, 1, 1, 1, 1, 1, 1],  # 0 = Start
         [1, 0, 1, 1, 1, 1, 1],  # 1 = Bunny 0
         [1, 1, 0, 1, 1, 1, 1],  # 2 = Bunny 1
         [1, 1, 1, 0, 1, 1, 1],  # 3 = Bunny 2
         [1, 1, 1, 1, 0, 1, 1],  # 4 = Bunny 3
         [1, 1, 1, 1, 1, 0, 1],  # 5 = Bunny 4
         [1, 1, 1, 1, 1, 1, 0]  # 6 = Bulkhead
     ]
     # Sequential path distance = 1 + 1 + 1 + 1 = 6
     # Best path: 0, 1, 2, 3, 4, 5, 6; distance = 6
     time_limit = sys.maxint
     self.assertEqual(answer(times, time_limit), [0, 1, 2, 3, 4])
Example #10
0
 def test_answer_1(self):
     """ 
     Simple symmetrical paths, no time limit
     """
     times = [
         [0, 10, 5, 1, 1],  # 0 = Start
         [10, 0, 3, 1, 1],  # 1 = Bunny 0
         [5, 3, 0, 2, 1],  # 2 = Bunny 1
         [1, 1, 2, 0, 1],  # 3 = Bunny 2
         [1, 1, 1, 1, 0]  # 4 = Bulkhead
     ]
     # Sequential path distance = 10 + 3 + 2 + 1 = 16
     # Best path: 0, 3, 1, 2, 4; distance = 1 + 1 + 3 + 1 = 6
     time_limit = sys.maxint
     self.assertEqual(answer(times, time_limit), [0, 1, 2])
Example #11
0
 def test_answer_provided1(self):
     """
     This case is undirected/symmetrical with no negative weights or negative-weighted cycles, and CANNOT be solved
     within the time limit.
     So the standard TSP should work with the addition of handling the time-limit bound.
     """
     times = [
         [0, 1, 1, 1, 1],  # 0 = Start
         [1, 0, 1, 1, 1],  # 1 = Bunny 0
         [1, 1, 0, 1, 1],  # 2 = Bunny 1
         [1, 1, 1, 0, 1],  # 3 = Bunny 2
         [1, 1, 1, 1, 0]  # 4 = Bulkhead
     ]
     time_limit = 3
     self.assertEqual(answer(times, time_limit), [0, 1])
Example #12
0
    def test_dogefu(self):
        # reddit.com/r/dogecoin/comments/303sj9/dogefu_key_origami/

        #input_key = '6KUsZfnpC35S4J92BiJfY6g7oi94PDwiHDPFxUAzkQtfdut2oWw'

        # Swap first and last blocks
        #input_key = '6 t2oWw npC35 S4J92 BiJfY 6g7oi 94PDw iHDPF xUAzk Qtfdu KUsZf'

        # Swap first and second halves
        #input_key = '6 94PDw iHDPF xUAzk Qtfdu t2oWw KUsZf npC35 S4J92 BiJfY 6g7oi'

        # Reverse characters of first block
        #input_key = '6 wDP49 iHDPF xUAzk Qtfdu t2oWw KUsZf npC35 S4J92 BiJfY 6g7oi'

        input_key = '6wDP49iHDPFxUAzkQtfdut2oWwKUsZfnpC35S4J92BiJfY6g7oi'
        public_key = 'DPXVGzs1ttpo1sDQ6xaqCc8WRY1HPurn3i'
        self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #13
0
 def test_answer_2(self):
     """ 
     This case is undirected/symmetrical with no negative weights or negative-weighted cycles, and all bunnies
     can be rescued within the time limit.
     So the standard TSP should work -- except we end at bulkhead node, not back at the start.
     """
     times = [
         [0, 1, 1, 1, 1],  # 0 = Start
         [1, 0, 1, 1, 1],  # 1 = Bunny 0
         [1, 1, 0, 1, 1],  # 2 = Bunny 1
         [1, 1, 1, 0, 1],  # 3 = Bunny 2
         [1, 1, 1, 1, 0]  # 4 = Bulkhead
     ]
     # Sequential path distance = 1 + 1 + 1 + 1 = 4
     # Best path: 0, 1, 2, 3, 4; distance = 4
     time_limit = sys.maxint
     self.assertEqual(answer(times, time_limit), [0, 1, 2])
Example #14
0
    def test_dogefu(self):
        # reddit.com/r/dogecoin/comments/303sj9/dogefu_key_origami/

        #input_key = '6KUsZfnpC35S4J92BiJfY6g7oi94PDwiHDPFxUAzkQtfdut2oWw'

        # Swap first and last blocks
        #input_key = '6 t2oWw npC35 S4J92 BiJfY 6g7oi 94PDw iHDPF xUAzk Qtfdu KUsZf'

        # Swap first and second halves
        #input_key = '6 94PDw iHDPF xUAzk Qtfdu t2oWw KUsZf npC35 S4J92 BiJfY 6g7oi'

        # Reverse characters of first block
        #input_key = '6 wDP49 iHDPF xUAzk Qtfdu t2oWw KUsZf npC35 S4J92 BiJfY 6g7oi'

        input_key = '6wDP49iHDPFxUAzkQtfdut2oWwKUsZfnpC35S4J92BiJfY6g7oi'
        public_key = 'DPXVGzs1ttpo1sDQ6xaqCc8WRY1HPurn3i'
        self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #15
0
 def test_answer(self):
     for test_parameter in TestParameters:
         actual = answer(test_parameter.list_)
         self.assertEqual(actual, test_parameter.last)
Example #16
0
 def testSamples(self):
     self.assertEqual(s.answer(0), 2)
     self.assertEqual(s.answer(9), 2)
     self.assertEqual(s.answer(42), 4)
Example #17
0
 def test_empty_string(self):
     self.assertEqual(answer(""), 0)
Example #18
0
 def test_pattern_with_arity_4(self):
     self.assertEqual(answer("abcabcabcabc"), 4)
Example #19
0
from solution import answer


answer(["annie", "bonnie", "liz"])
answer(['java', 'python', 'ruby', 'c', 'r', 'ab'])
Example #20
0
 def test_final(self):
     input_key = '6KTnTsUJ1cryy3Kyb28yWNuiWiTvvMWU1MtHYiN4oMRTeDqb9jD'
     public_key = 'DQ7Ys3fkuCHjt5dg4yHTcNB8t7FwM3AQSJ'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #21
0
 def test_3swaps(self):
     input_key = '6PJUiyB8BBcydqpMLyoadMWuWyhBxsaRu2YPpMRrfa93tRhKQ79'
     public_key = 'DHjmUqaaYBfDpyFvD9H8RjafbFy7cU5fGa'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #22
0
 def test_namesumlist(self):
     self.assertEqual(answer(['annie', 'bonnie', 'liz'])['name_sum_list'], [[43, 'annie'], [59, 'bonnie'], [47, 'liz']])
Example #23
0
def test_answer():
    eq_(['L', 'R'], solution.answer(2))
    eq_(['L', '-', 'R'], solution.answer(8))
    eq_(['R'], solution.answer(1))
    eq_(['-', 'L', 'R', 'L', 'R'], solution.answer(60))
Example #24
0
 def test_output(self):
     self.assertEqual(answer(['annie', 'bonnie', 'liz'])['output'], ['bonnie', 'liz', 'annie'])
Example #25
0
 def test_samesumsort(self):
     self.assertEqual(answer(['java', 'python', 'ruby', 'c', 'r', 'ab'])['output'], ['python', 'ruby', 'java', 'r', 'c', 'ab'])
Example #26
0
 def test_listlist(self):
     self.assertEqual(answer(['annie', 'bonnie', 'liz'])['list_list'], [[1, 14, 14, 9, 5], [2, 15, 14, 14, 9, 5], [12, 9, 26]])
Example #27
0
 def test_big_list(self):
     list_ = range(100000000000000000000000000000)
     last = 99999999999999999999999999999
     actual = answer(list_)
     self.assertEqual(actual, last)
Example #28
0
 def test_sumlist(self):
     self.assertEqual(answer(['annie', 'bonnie', 'liz'])['sum_list'], [43, 59, 47])
Example #29
0
from solution import answer
answer_list = [
    answer([1, 4, 2, 5, 1, 2, 3]),
    answer([1, 2, 3, 2, 1])
]

for answers in answer_list:
    print answers
Example #30
0
 def test_answer_repeating_len_9(self):
     lst = [6] * 9
     self.assertEqual(answer(lst), 84)
Example #31
0
def test_answer():
    eq_(2, answer(["foo", "bar", "oof", "bar"]))
    eq_(5, answer(["x", "y", "xy", "yy", "", "yx"]))
Example #32
0
 def test_base(self):
     input_key = '6JUPiyB8BBcydqprLyoadMWuWyhBxsaRu2YPpMRMfa93tRhKQ97'
     public_key = 'DHjmUqaaYBfDpyFvD9H8RjafbFy7cU5fGa'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #33
0
 def test_3swaps(self):
     input_key = '6PJUiyB8BBcydqpMLyoadMWuWyhBxsaRu2YPpMRrfa93tRhKQ79'
     public_key = 'DHjmUqaaYBfDpyFvD9H8RjafbFy7cU5fGa'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #34
0
 def test_pattern_with_arity_2(self):
     self.assertEqual(answer("abccbaabccba"), 2)
Example #35
0
 def test_final(self):
     input_key = '6KTnTsUJ1cryy3Kyb28yWNuiWiTvvMWU1MtHYiN4oMRTeDqb9jD'
     public_key = 'DQ7Ys3fkuCHjt5dg4yHTcNB8t7FwM3AQSJ'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #36
0
 def test_no_pattern(self):
     self.assertEqual(answer("asdfghjkl"), 0)
Example #37
0
 def test_answer(self):
     self.assertEqual(answer(12), [9, 1, 1, 1])
     self.assertEqual(answer(15324), [15129, 169, 25, 1])
Example #38
0
 def test_none_type(self):
     self.assertEqual(answer(None), 0)
Example #39
0
 def test_answer_repeating_len_100(self):
     lst = [6] * 100
     self.assertEqual(answer(lst), 161700)
Example #40
0
 def test_answer(self):
     self.assertEqual(["L", "R"], solution.answer(2))
     self.assertEqual(["L", "-", "R"], solution.answer(8))
     self.assert_commands_balance(
         (1000000000, 0, 1, 2, 3, 4, 5, 7, 11, 13, 14, 15, 20, 26, 27, 28,
          78, 90, 99, 101, 240, 242, 243, 832, 777, 12345678))
Example #41
0
 def test_answer_repeating_len_500(self):
     lst = [6] * 500
     self.assertEqual(answer(lst), 20708500)
Example #42
0
 def test_answer_empty_list(self):
     with self.assertRaises(IndexError) as context:
         list_ = []
         answer(list_)
Example #43
0
from solution import answer
answer_list = [
    answer([[0, 1], [1, 2], [2, 3], [3, 5], [4, 5]]),
    answer([[0, 1000000], [42, 43], [0, 1000000], [42, 43]]),
]

for answers in answer_list:
    print answers
Example #44
0
 def test_answer_repeating_len_12(self):
     lst = [6] * 12
     self.assertEqual(answer(lst), 220)
Example #45
0
 def test_answer(self):
     self.assertEqual(answer(["1.1.2", "1.0", "1.3.3", "1.0.12", "1.0.2"]),
             ["1.0", "1.0.2", "1.0.12", "1.1.2", "1.3.3"])
     self.assertEqual(answer(["1.11", "2.0.0", "1.2", "2", "0.1", "1.2.1",
         "1.1.1", "2.0"]), ["0.1", "1.1.1", "1.2", "1.2.1", "1.11", "2",
             "2.0", "2.0.0"])
Example #46
0
 def subject(self, *args):
     return solution.answer(*args)
Example #47
0
 def test_answer_repeating_len_15(self):
     lst = [6] * 15
     self.assertEqual(answer(lst), 455)
Example #48
0
 def test_answer_repeating_len_18(self):
     lst = [6] * 18
     self.assertEqual(answer(lst), 816)
Example #49
0
 def test_answer_provided2(self):
     self.assertEqual(answer([1, 2, 3, 4, 5, 6]), 3)
Example #50
0
 def test_base(self):
     input_key = '6JUPiyB8BBcydqprLyoadMWuWyhBxsaRu2YPpMRMfa93tRhKQ97'
     public_key = 'DHjmUqaaYBfDpyFvD9H8RjafbFy7cU5fGa'
     self.assertEqual(solution.answer(input_key, public_key), public_key)
Example #51
0
from solution import answer

# Ask user for a start and end for the range of weights to test
while True:
	start = input("Enter an integer (between 0 and 10^9) from where to start the test range: ")
	end = input("Enter an integer (between 0 and 10^9) from where to end the test range: ")
	if(start > end):
		print("The end occurs after the beginning: \n\tStart:%d \n\tEnd:%d" %(start,end))
	elif(end > pow(10,9)):
		print("Start or end is out of bounds; pick a start or end in the bounds of 0 to 10^9")
	else:
		for i in range(start,end):
			print "%d: " %(i),answer(i)