Example #1
0
    def test_life_the_universe_and_everything(self):
        step_count = 0
        time_total = 0
        num_of_matrixs = 1000
        for count_matrix in range(1, num_of_matrixs + 1):
            filename = os.path.join('../matrices',
                                    'matrix') + str(count_matrix) + '.txt'
            matrix = self.read_matrix_file(filename)
            matrix_copy = matrix.copy()
            t_start = time.time()
            douglas = hiker.Hiker()
            move_actions = douglas.draw_line(matrix_copy)
            t_end = time.time()
            time_total += t_end - t_start
            # print_move_action(move_actions)

            try:
                matrix = self.move_matrix(matrix, move_actions)
                # print_matrix(matrix)
                if not self.is_line_matrix(matrix):
                    raise Exception('置换后的矩阵,所有1元素没有形成一条直线。')
                step_count += (0
                               if move_actions is None else len(move_actions))
                print('测试矩阵' + filename + '成功')
                print('耗费步数:' + str(step_count))
            except Exception as e:
                print('测试矩阵' + filename + '失败')
                print(e)
        print('总步数:' + str(step_count))
        print('总耗时:' + str(time_total * 1000) + 'ms')
Example #2
0
 def test_check_if_number_of_lines_is_not_equal_to_three(self):
     '''simple example to start you off'''
     tester = hiker.Hiker()
     with self.assertRaises(ValueError):
         tester_string = "happy purple frog/eating bugs in the marshes"
         tester.haiku(tester_string)
     with self.assertRaises(ValueError):
         tester_string = "happy purple frog/eating bugs in the marshes/get indigestion/extra line for test"
         tester.haiku(tester_string)
def test_is_isbn_thirteen_true_another_number():
    douglas = hiker.Hiker('978-0596809485')
    assert douglas.is_isbn() is True
def test_is_isbn_thirteen_true():
    douglas = hiker.Hiker('978-0-13-  149505- 0')
    assert douglas.is_isbn() is True
def test_check_digit():
    douglas = hiker.Hiker('978-0-13-  149505- 4')
    assert douglas._check_digit() == 4
Example #6
0
 def test_if_contains_numbers(self):
     tester = hiker.Hiker()
     with self.assertRaises(ValueError):
         tester_string = "happy purple frog/eating bugs in the5 marshes6/get indigestion"
         tester.haiku(tester_string)
Example #7
0
def test_life_the_universe_and_everything():
    '''a simple example to start you off'''
    douglas = hiker.Hiker()
    assert douglas.answer() == 42
def test_valid_isbn_standard_valid_13():
    douglas = hiker.Hiker('0471958697', 13)
    assert douglas._valid_isbn_standard() is True
def test_isbn_ten_is_valid():
    douglas = hiker.Hiker('0471958697', 10)
    assert douglas.is_isbn() is True
def test_isbn_is_correct_number_digits_is_false_if_not_all_digits():
    douglas = hiker.Hiker('978-0-1A-  149505- 0')
    assert douglas._isbn_is_correct_number_of_digits() is False
Example #11
0
 def test_input_has_no_vowels(self):
     tester = hiker.Hiker()
     tester_string = "bbbb bbbb bbbb/ccc ccc ccc/ddd ddd ddd"
     self.assertEqual(tester.haiku(tester_string), (3, 3, 3, 'No'))
Example #12
0
 def test_input_multiple_whitespace(self):
     tester = hiker.Hiker()
     tester_string = "happy purple frog/eating   bugs in the   marshes/get   indigestion"
     self.assertEqual(tester.haiku(tester_string), (5, 7, 5, 'Yes'))
Example #13
0
 def test_input_more_than_two_contiguous_vowels(self):
     tester = hiker.Hiker()
     tester_string = "happy purple frog/eeeeeeating bugs in the marsheeeeees/get indigeeeeestion"
     self.assertEqual(tester.haiku(tester_string), (5, 7, 5, 'Yes'))
Example #14
0
 def test_input_greater_than_200_characters(self):
     tester = hiker.Hiker()
     with self.assertRaises(ValueError):
         tester_string = "happy purple froghappy purple froghappy purple froghappy purple frog/eeeeating bugs in the marsheeeeseeeeating bugs in the marsheeees/get indigeeeestionget indigeeeestionget indigeeeestionget indigeeeestion"
         tester.haiku(tester_string)
def test_isbn_calculator():
    douglas = hiker.Hiker('978-0596809485')
    assert douglas._isbn_calculator() == 5
def test_isbn_is_correct_number_of_digits_is_false_if_not_length_thirteen():
    douglas = hiker.Hiker('97-  149505- 0')
    assert douglas._isbn_is_correct_number_of_digits() is False
def test_isbn_calculator_another():
    douglas = hiker.Hiker('978-0-13-  149505- 0')
    assert douglas._isbn_calculator() == 0
def test_is_isbn_thirteen_returns_false():
    douglas = hiker.Hiker('97-  149505- 0')
    assert douglas.is_isbn() is False
def test_valid_isbn_standard_invalid():
    douglas = hiker.Hiker('0471958697', 5)
    assert douglas._valid_isbn_standard() is False
def test_remove_hyphens_and_spaces():
    douglas = hiker.Hiker('978-0-13-  149505- 0')
    assert douglas.isbn == '9780131495050'
def test_isbn_is_thirteen_digits():
    douglas = hiker.Hiker('978-0-13-  149505- 0')
    assert douglas._isbn_is_correct_number_of_digits() is True
def test_calculate_sums():
    douglas = hiker.Hiker('978-0-13-  149505- 4')
    assert douglas._calculate_sums_for_isbn_thirteen() == 100
Example #23
0
 def test_life_the_universe_and_everything(self):
     '''a simple example to start you off'''
     douglas = hiker.Hiker()
     self.assertEqual(douglas.answer(), 42)
Example #24
0
 def test_if_contains_uppercase(self):
     tester = hiker.Hiker()
     with self.assertRaises(ValueError):
         tester_string = "happy purple frog/eating bugs in the marshes/GEt indigestion"
         tester.haiku(tester_string)