예제 #1
0
    def test_get_word_without_changes(self):
        regex = re.compile(r'[\w\d\'\"-]+')

        list = ['qwerty', 'qwer', 'qwe']
        self.assertEqual(list, get_words(list, regex))

        list = ['non-stop', '"Test"']
        self.assertEqual(['non-stop', '"Test"'], get_words(list, regex))
예제 #2
0
    def test_get_changed_list(self):
        regex = re.compile(r'[\w\d\'\"-]+')

        data = ['hello', 'a=', 'split!']
        self.assertEqual(['hello', 'a', 'split'], get_words(data, regex))

        data = ['a=a', '13!=12']
        self.assertEqual(['a', 'a', '13', '12'], get_words(data, regex))

        data = ['It\'s', ',asd,d', '===']
        self.assertEqual(['It\'s', 'asd', 'd'], get_words(data, regex))
예제 #3
0
def test_get_words_middle_hor():
    #Includes middle word with no accessory words
    tiles = build_tiles(8, 8)

    #Test single word
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[12].update_letter('h')
    tiles[12].update_height()
    tiles[13].update_letter('e')
    tiles[13].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'the'
    assert len(heights) == 1
    assert heights[0] == 3

    #Test word with middle word up
    tiles[4].update_letter('o')
    tiles[4].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'oh'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with middle word down
    tiles[4].update_letter(0)
    tiles[20].update_letter('i')
    tiles[20].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'hi'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with middle word both up and down
    tiles[4].update_letter('o')

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'ohi'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #4
0
def test_get_words_middle_vert():
    #Includes middle word with no accessory words
    tiles = build_tiles(8, 8)

    #Test single word
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'the'
    assert len(heights) == 1
    assert heights[0] == 3

    #Test word with middle word right
    tiles[20].update_letter('o')
    tiles[20].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'ho'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with middle word left
    tiles[20].update_letter(0)
    tiles[18].update_letter('i')
    tiles[18].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'ih'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with middle word both right and left
    tiles[20].update_letter('o')

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'iho'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #5
0
def test_get_words_diagonal_vert():
    #Test letter diagonal top left
    tiles = build_tiles(8, 8)

    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()
    tiles[35].update_letter('r')
    tiles[35].update_height()
    tiles[43].update_letter('e')
    tiles[43].update_height()
    tiles[2].update_letter('h')
    tiles[2].update_height()

    words, heights, touch = get_words('there', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal top right
    tiles[4].update_letter('h')
    tiles[4].update_height()

    words, heights, touch = get_words('there', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal bottom left
    tiles[50].update_letter('h')
    tiles[50].update_height()

    words, heights, touch = get_words('there', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal bottom right
    tiles[52].update_letter('h')
    tiles[52].update_height()

    words, heights, touch = get_words('there', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5
예제 #6
0
def test_get_words_diagonals_hor():
    #Test letter diagonal top left
    tiles = build_tiles(8, 8)

    tiles[17].update_letter('t')
    tiles[17].update_height()
    tiles[18].update_letter('h')
    tiles[18].update_height()
    tiles[19].update_letter('e')
    tiles[19].update_height()
    tiles[20].update_letter('r')
    tiles[20].update_height()
    tiles[21].update_letter('e')
    tiles[21].update_height()
    tiles[8].update_letter('h')
    tiles[8].update_height()

    words, heights, touch = get_words('there', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal top right
    tiles[14].update_letter('h')
    tiles[14].update_height()

    words, heights, touch = get_words('there', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal bottom left
    tiles[24].update_letter('h')
    tiles[24].update_height()

    words, heights, touch = get_words('there', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test letter diagonal bottom right
    tiles[30].update_letter('h')
    tiles[30].update_height()

    words, heights, touch = get_words('there', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5
예제 #7
0
def test_get_words_multiple_vert():
    tiles = build_tiles(8, 8)

    #Test single word
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()
    tiles[26].update_letter('h')
    tiles[26].update_height()
    tiles[28].update_letter('h')
    tiles[28].update_height()

    #Test word with multiple accessory words
    tiles[10].update_letter('a')
    tiles[10].update_height()
    tiles[12].update_letter('o')
    tiles[12].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 3
    assert words[0] == 'the'
    assert words[1] == 'ato'
    assert words[2] == 'heh'
    assert len(heights) == 3
    assert heights[0] == 3
    assert heights[1] == 3
    assert heights[2] == 3
예제 #8
0
def test_get_words_end_vert():
    tiles = build_tiles(8, 8)

    #Create board
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()

    #Test word with end word right
    tiles[28].update_letter('h')
    tiles[28].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'eh'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with end word left
    tiles[28].update_letter(0)
    tiles[26].update_letter('h')
    tiles[26].update_height()

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'he'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with end word right and left
    tiles[28].update_letter('h')

    words, heights, touch = get_words('the', (1, 3), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'heh'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #9
0
def test_get_word_end_hor():
    tiles = build_tiles(8, 8)

    #Create board
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[12].update_letter('h')
    tiles[12].update_height()
    tiles[13].update_letter('e')
    tiles[13].update_height()

    #Test word with end word up
    tiles[5].update_letter('h')
    tiles[5].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'he'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with end word down
    tiles[5].update_letter(0)
    tiles[21].update_letter('h')
    tiles[21].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'eh'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with end word up and down
    tiles[5].update_letter('h')

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'heh'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #10
0
def test_get_words_start_hor():
    tiles = build_tiles(8, 8)

    #Create board
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[12].update_letter('h')
    tiles[12].update_height()
    tiles[13].update_letter('e')
    tiles[13].update_height()

    #Test word with start word up
    tiles[3].update_letter('a')
    tiles[3].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'at'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with start word down
    tiles[3].update_letter(0)
    tiles[19].update_letter('o')
    tiles[19].update_height()

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'to'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 2

    #Test word with start word up and down
    tiles[3].update_letter('a')

    words, heights, touch = get_words('the', (1, 3), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'ato'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #11
0
def test_get_words_right():
    tiles = build_tiles(8, 8)

    #Test word on bottom row
    tiles[15].update_letter('t')
    tiles[15].update_height()
    tiles[23].update_letter('h')
    tiles[23].update_height()
    tiles[31].update_letter('e')
    tiles[31].update_height()
    tiles[13].update_letter('t')
    tiles[13].update_height()
    tiles[14].update_letter('h')
    tiles[14].update_height()

    words, heights, touch = get_words('the', (1, 7), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'tht'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #12
0
def test_get_words_left():
    #Test word on left edge
    tiles = build_tiles(8, 8)

    tiles[8].update_letter('t')
    tiles[8].update_height()
    tiles[16].update_letter('h')
    tiles[16].update_height()
    tiles[24].update_letter('e')
    tiles[24].update_height()
    tiles[25].update_letter('l')
    tiles[25].update_height()
    tiles[26].update_letter('f')
    tiles[26].update_height()

    words, heights, touch = get_words('the', (1, 0), -1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'elf'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #13
0
def test_get_words_bottom():
    tiles = build_tiles(8, 8)

    #Test word on bottom row
    tiles[58].update_letter('t')
    tiles[58].update_height()
    tiles[59].update_letter('h')
    tiles[59].update_height()
    tiles[60].update_letter('e')
    tiles[60].update_height()
    tiles[44].update_letter('t')
    tiles[44].update_height()
    tiles[52].update_letter('h')
    tiles[52].update_height()

    words, heights, touch = get_words('the', (7, 2), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'the'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #14
0
def test_get_words_top():
    #Test word on top row
    tiles = build_tiles(8, 8)

    tiles[2].update_letter('t')
    tiles[2].update_height()
    tiles[3].update_letter('h')
    tiles[3].update_height()
    tiles[4].update_letter('e')
    tiles[4].update_height()
    tiles[12].update_letter('l')
    tiles[12].update_height()
    tiles[20].update_letter('f')
    tiles[20].update_height()

    words, heights, touch = get_words('the', (0, 2), 1, tiles, 0)
    assert len(words) == 2
    assert words[0] == 'the'
    assert words[1] == 'elf'
    assert len(heights) == 2
    assert heights[0] == 3
    assert heights[1] == 3
예제 #15
0
 def test_empty_list(self):
     regex = re.compile(r'[\w\d\'\"-]+')
     self.assertEqual([], get_words([], regex))
예제 #16
0
def test_get_words_adding_vert():
    #Test adding on to start of a blank word
    tiles = build_tiles(8, 8)
    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()
    tiles[35].update_letter('r')
    tiles[35].update_height()
    tiles[43].update_letter('e')
    tiles[43].update_height()

    words, heights, touch = get_words('t', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to start of a word with cross words
    tiles[26].update_letter('e')
    tiles[26].update_height()
    tiles[28].update_letter('e')
    tiles[28].update_height()

    words, heights, touch = get_words('t', (1, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to end of a blank word
    tiles = build_tiles(8, 8)

    tiles[11].update_letter('t')
    tiles[11].update_height()
    tiles[19].update_letter('h')
    tiles[19].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()
    tiles[35].update_letter('r')
    tiles[35].update_height()
    tiles[43].update_letter('e')
    tiles[43].update_height()

    words, heights, touch = get_words('e', (5, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to end of a word with cross words
    tiles[26].update_letter('e')
    tiles[26].update_height()
    tiles[28].update_letter('e')
    tiles[28].update_height()

    words, heights, touch = get_words('e', (5, 3), -1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5
예제 #17
0
def test_get_words_adding_hor():
    #Test adding on to start of a blank word
    tiles = build_tiles(8, 8)
    tiles[17].update_letter('t')
    tiles[17].update_height()
    tiles[18].update_letter('h')
    tiles[18].update_height()
    tiles[19].update_letter('e')
    tiles[19].update_height()
    tiles[20].update_letter('r')
    tiles[20].update_height()
    tiles[21].update_letter('e')
    tiles[21].update_height()

    words, heights, touch = get_words('t', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to start of a word with cross words
    tiles[11].update_letter('e')
    tiles[11].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()

    words, heights, touch = get_words('t', (2, 1), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to end of a blank word
    tiles = build_tiles(8, 8)

    tiles[17].update_letter('t')
    tiles[17].update_height()
    tiles[18].update_letter('h')
    tiles[18].update_height()
    tiles[19].update_letter('e')
    tiles[19].update_height()
    tiles[20].update_letter('r')
    tiles[20].update_height()
    tiles[21].update_letter('e')
    tiles[21].update_height()

    words, heights, touch = get_words('e', (2, 5), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5

    #Test adding on to end of a word with cross words
    tiles[11].update_letter('e')
    tiles[11].update_height()
    tiles[27].update_letter('e')
    tiles[27].update_height()

    words, heights, touch = get_words('e', (2, 5), 1, tiles, 0)
    assert len(words) == 1
    assert words[0] == 'there'
    assert len(heights) == 1
    assert heights[0] == 5