Esempio n. 1
0
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()

    def tearDown(self):
        del self.controller

    '''
    Now lets test the more difficult stuff
    EK, Test the GUI in game...
    '''

    def test_hasFocus(self):
        '''Test the GUI in its default state'''
        # when we start the game, has Button '0' the focus?
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 0:
                self.assertTrue(self.controller.view.buttons[i].hasFocus())

    def test_hasFocus1(self):
        #after successfully clicing 5 times, does button 4 have the focus?
        for g in range(5):
            p = [
                i for i in range(15)
                if (int(self.controller.view.buttons[i].text()) == g)
            ]
            #self.controller.show()
            self.controller.view.buttons[p[0]].click()
            #self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 4:
                self.assertTrue(self.controller.view.buttons[i].hasFocus())

    def test_hasFocus2(self):
        # clicking the right buttons all along
        # when we start the game, has Button '0' the focus and each correctly clicked button afterwards has focus ?
        for g in range(
                14
        ):  #the 14th button will be disabled immediately so cannot have focus anymore
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #self.controller.show()
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus3(self):
        # clicking whatever buttons all along
        # when we play the game, each clicked button has focus ?
        for g in range(
                50
        ):  #Attention, somewhen this might eventually fail bec a shuffle will come in its way
            self.controller.show(
            )  # show is needed for so many clicks. Until ~range 20 it will do without show
            self.controller.view.buttons[g % 15].click()
            self.assertTrue(self.controller.view.buttons[g % 15].hasFocus())

    def test_hasFocus4(self):
        # clicking whatever buttons all along
        # when we play the game, each clicked button has focus ?
        #self.controller.view.timer.stop()
        for g in range(50):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g % 15
            ]
            self.controller.show(
            )  # show is needed for so many clicks. Until ~range 20 it will do without show
            self.controller.view.buttons[p[0]].click()
            #time.sleep(1)
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus5(self):
        # Are all buttons without focus after successful 7 clicks, a reShuffle and a successful finish
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        self.controller.reshuffle()
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].hasFocus() == False)

    def test_hasFocus6(self):
        # After a reShuffle when Button 6 had focus before, does it still have focus afterwards?
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        self.controller.reshuffle()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())

    def test_hasFocus7(self):
        # Are all buttons with focus during successful 7 clicks, a reShuffle and a successful continuation
        # but the very last button looses its focus when clicked since it gets disable immediaely!
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        self.controller.reshuffle()
        for g in range(6, 14):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.view.buttons[p[0]].hasFocus())
        for g in range(14, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(
                self.controller.view.buttons[p[0]].hasFocus() == False)

    def test_isDisabled(self):
        # is button 0 disabled after button 0 and button 1 was hitted successfully?
        for g in range(2):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            if int(self.controller.view.buttons[i].text()) == 0:
                self.assertTrue(
                    self.controller.view.buttons[i].isEnabled() == False)

    def test_isDisabled1(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # all remaining buttons are still enabled
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)

    def test_isDisabled2(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # not button 7 is hitted correctly now
        # is Button 6 now disabled?
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(7, 8):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)

    def test_isDisabled3(self):
        # is button 0 to 5 disabled after button 6 was hitted successfully?
        # but button 6 is not yet disabled
        # not button 10 is hitted in error
        # is Button 6 still enabled?
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == False)
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)
        for g in range(10, 11):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for g in range(6, 7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.assertTrue(
                self.controller.view.buttons[p[0]].isEnabled() == True)

    def test_isDisabled4(self):
        # Are all buttons disabled after a successful run?
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].isEnabled() == False)

    def test_isDisabled5(self):
        # Are all buttons disabled after a successful 7 clicks, a reShuffle and a successful finish
        for g in range(7):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        self.controller.reshuffle()
        for g in range(7, 15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
        for i in range(15):
            #if int(self.controller.view.buttons[i].text()) == 0:
            self.assertTrue(
                self.controller.view.buttons[i].isEnabled() == False)

    '''
    EK is there a timer to reshuffle the numbers in game?
    '''

    def test_isthereaTimer(self):
        self.assertIsNone(self.controller.view.timer.stop())

    def test_Timer1(self):
        self.assertTrue(self.controller.view.timer.interval() == 2000)

    def test_Timer2(self):
        self.assertIsNone(self.controller.view.timer.start())

    def test_Timer3(self):
        # does the timer call reShuffle and does reShuffle really shuffle?
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        self.assertIsNone(self.controller.view.timer.setInterval(1))
        #self.controller.reShuffle()
        self.controller.show()
        list1 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list1)
        #print("Intervall = ", str(self.controller.view.timer.interval()))
        self.assertTrue(list0 != list1)

    def test_Timer4(self):
        self.assertIsNone(self.controller.view.timer.setInterval(2000))

    def test_Timer5(self):
        self.assertIsNone(self.controller.view.timer.start())
Esempio n. 2
0
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()

    def tearDown(self):
        del self.controller

    '''
    Now lets have fun, lets play
    Test the GUI in game...
    '''

    def test_ClickButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 1)

    def test_ClickButtonNum01(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 1)
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 1
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[p[0]].click()
        self.assertTrue(self.controller.model.isCorrect == 2)

    def test_ClickAllButtonsCorrectly(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isCorrect == g + 1)

    def test_ClickAllButtonsCorrectly2(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isTotal == g + 1)

    def test_ClickAllButtonsCorrectly3(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isOpen == 14 - g)

    def test_ClickAllButtonsCorrectly4(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isWrong == 0)

    def test_ClickAllButtonsCorrectly5(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.Ngame == 1)

    def test_ClickWrongButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        #print("Button with 0 is ", str(p))
        self.controller.view.buttons[(p[0] + 1) % 15].click()
        self.assertTrue(self.controller.model.isCorrect == 0)
        self.assertTrue(self.controller.model.isWrong == 1)
        self.assertTrue(self.controller.model.isOpen == 15)
        self.assertTrue(self.controller.model.isTotal == 1)
        self.assertTrue(self.controller.model.Ngame == 1)

    def test_Click30TimesWrongButton(self):
        ''' Test the GUI in game '''
        for e in range(30):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            #print("Button with 0 is ", str(p))
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == e + 1)
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isTotal == e + 1)
            self.assertTrue(self.controller.model.Ngame == 1)

    def test_Click3TimesWrongThenStartaNewErrorFreeGame(self):
        ''' Test the GUI in game '''
        for e in range(3):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            #print("Button with 0 is ", str(p))
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == e + 1)
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isTotal == e + 1)
            self.assertTrue(self.controller.model.Ngame == 1)
        self.controller.view.pushButton_Neu.click()
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            #print("Button with ", str(g), " is ", str(p))
            self.controller.view.buttons[p[0]].click()
            self.assertTrue(self.controller.model.isOpen == 14 - g)
            self.assertTrue(self.controller.model.isCorrect == g + 1)
            self.assertTrue(self.controller.model.isWrong == 0)
            self.assertTrue(self.controller.model.isTotal == g + 1)
            self.assertTrue(self.controller.model.Ngame == 2)

    def test_Click10timesNewGameOnly(self):
        ''' Test the GUI in game '''
        for g in range(10):
            self.controller.view.pushButton_Neu.click()
            self.assertTrue(self.controller.model.isOpen == 15)
            self.assertTrue(self.controller.model.isCorrect == 0)
            self.assertTrue(self.controller.model.isWrong == 0)
            self.assertTrue(self.controller.model.isTotal == 0)
            self.assertTrue(self.controller.model.Ngame == g + 2)

    def test_DispClickButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "1")

    def test_DispClickButtonNum01(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "1")
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 1
        ]
        self.controller.view.buttons[p[0]].click()
        self.assertEqual(self.controller.view.lineEdit_1.text(), "2")

    def test_DispClickAllButtonsCorrectly(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             g + 1)

    def test_DispClickAllButtonsCorrectly2(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             g + 1)

    def test_DispClickAllButtonsCorrectly3(self):
        ''' Test the GUI in game '''
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             14 - g)
            self.assertEqual(int(self.controller.view.lineEdit_2.text()), 0)
            self.assertEqual(int(self.controller.view.lineEdit_4.text()), 1)

    def test_DispClickWrongButtonNum0(self):
        ''' Test the GUI in game '''
        p = [
            i for i in range(15)
            if int(self.controller.view.buttons[i].text()) == 0
        ]
        self.controller.view.buttons[(p[0] + 1) % 15].click()
        self.assertEqual(int(self.controller.view.lineEdit_0.text()), 15)  #op
        self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                         0)  #correct
        self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                         1)  #wrong
        self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                         1)  #total
        self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                         1)  #Ngame

    def test_DispClick30TimesWrongButton(self):
        ''' Test the GUI in game '''
        for e in range(30):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             e + 1)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             e + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             1)  #Ngame

    def test_DispClick3TimesWrongThenStartaNewErrorFreeGame(self):
        ''' Test the GUI in game '''
        for e in range(3):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == 0
            ]
            self.controller.view.buttons[(p[0] + 2) % 15].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             e + 1)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             e + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             1)  #Ngame
        self.controller.view.pushButton_Neu.click()
        for g in range(15):
            p = [
                i for i in range(15)
                if int(self.controller.view.buttons[i].text()) == g
            ]
            self.controller.view.buttons[p[0]].click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             14 - g)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             g + 1)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             0)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             g + 1)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             2)  #Ngame

    def test_DispClick10timesNewGameOnly(self):
        ''' Test the GUI in game '''
        for g in range(10):
            self.controller.view.pushButton_Neu.click()
            self.assertEqual(int(self.controller.view.lineEdit_0.text()),
                             15)  #op
            self.assertEqual(int(self.controller.view.lineEdit_1.text()),
                             0)  #correct
            self.assertEqual(int(self.controller.view.lineEdit_2.text()),
                             0)  #wrong
            self.assertEqual(int(self.controller.view.lineEdit_3.text()),
                             0)  #total
            self.assertEqual(int(self.controller.view.lineEdit_4.text()),
                             g + 2)  #Ngame
class MyGameTestDefaultState(unittest.TestCase):
    def setUp(self):
        self.controller = GameController()
        self.controller.show()
        self.xybh = [
            (130, 180, 75, 23), (210, 180, 75, 23), (290, 180, 75, 23),
            (370, 180, 75, 23), (450, 180, 75, 23), (130, 150, 75, 23),
            (210, 150, 75, 23), (290, 150, 75, 23), (370, 150, 75, 23),
            (450, 150, 75, 23), (130, 120, 75, 23), (210, 120, 75, 23),
            (290, 120, 75, 23), (370, 120, 75, 23), (450, 120, 75, 23)
        ]

    def tearDown(self):
        del self.controller
        del self.xybh

    '''
    Test the GUI in its default state
    '''

    def test_layoutButton0(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.buttons[0].geometry(),
                         QtCore.QRect(130, 180, 75, 23))

    def test_layoutButton1(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[1]
        self.assertEqual(self.controller.view.buttons[1].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton2(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[2]
        self.assertEqual(self.controller.view.buttons[2].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton3(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[3]
        self.assertEqual(self.controller.view.buttons[3].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton4(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[4]
        self.assertEqual(self.controller.view.buttons[4].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton5(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[5]
        self.assertEqual(self.controller.view.buttons[5].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton6(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[6]
        self.assertEqual(self.controller.view.buttons[6].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton7(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[7]
        self.assertEqual(self.controller.view.buttons[7].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton8(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[8]
        self.assertEqual(self.controller.view.buttons[8].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton9(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[9]
        self.assertEqual(self.controller.view.buttons[9].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton10(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[10]
        self.assertEqual(self.controller.view.buttons[10].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton11(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[11]
        self.assertEqual(self.controller.view.buttons[11].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton12(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[12]
        self.assertEqual(self.controller.view.buttons[12].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton13(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[13]
        self.assertEqual(self.controller.view.buttons[13].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutButton14(self):
        '''Test the GUI in its default state'''
        x, y, b, h = self.xybh[14]
        self.assertEqual(self.controller.view.buttons[14].geometry(),
                         QtCore.QRect(x, y, b, h))

    def test_layoutAllButtons(self):
        '''Test the GUI in its default state'''
        for i in range(15):
            x, y, b, h = self.xybh[i]
            self.assertEqual(self.controller.view.buttons[i].geometry(),
                             QtCore.QRect(x, y, b, h))

    def test_layoutLabel(self):
        self.assertEqual(self.controller.view.label.geometry(),
                         QtCore.QRect(130, 60, 391, 31))

    def test_layoutLabel2(self):
        self.assertEqual(self.controller.view.label_2.geometry(),
                         QtCore.QRect(20, 240, 41, 16))

    def test_layoutLabel3(self):
        self.assertEqual(self.controller.view.label_3.geometry(),
                         QtCore.QRect(20, 210, 41, 16))

    def test_layoutLabel4(self):
        self.assertEqual(self.controller.view.label_4.geometry(),
                         QtCore.QRect(20, 180, 41, 16))

    def test_layoutLabel5(self):
        self.assertEqual(self.controller.view.label_5.geometry(),
                         QtCore.QRect(20, 150, 41, 16))

    def test_layoutLabel6(self):
        self.assertEqual(self.controller.view.label_6.geometry(),
                         QtCore.QRect(20, 120, 41, 16))

    def test_lineEdit_0(self):
        self.assertEqual(self.controller.view.lineEdit_0.geometry(),
                         QtCore.QRect(70, 120, 31, 20))

    def test_lineEdit_1(self):
        self.assertEqual(self.controller.view.lineEdit_1.geometry(),
                         QtCore.QRect(70, 150, 31, 20))

    def test_lineEdit_2(self):
        self.assertEqual(self.controller.view.lineEdit_2.geometry(),
                         QtCore.QRect(70, 180, 31, 20))

    def test_lineEdit_3(self):
        self.assertEqual(self.controller.view.lineEdit_3.geometry(),
                         QtCore.QRect(70, 210, 31, 20))

    def test_lineEdit_4(self):
        self.assertEqual(self.controller.view.lineEdit_4.geometry(),
                         QtCore.QRect(70, 240, 31, 20))

    def test_pushButton_Neu(self):
        self.assertEqual(self.controller.view.pushButton_Neu.geometry(),
                         QtCore.QRect(210, 240, 75, 23))

    def test_pushButton_End(self):
        self.assertEqual(self.controller.view.pushButton_End.geometry(),
                         QtCore.QRect(370, 240, 75, 23))

    def test_defaults0(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_2.text(), "Spiele")

    def test_defaults1(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_3.text(), "gesamt")

    def test_defaults2(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_4.text(), "falsch")

    def test_defaults3(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_5.text(), "korrekt")

    def test_defaults4(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.label_6.text(), "offen")

    def test_defaults5(self):
        '''Test the GUI in its default state'''
        self.assertEqual(
            self.controller.view.label.text(),
            "<html><head/><body><p align=\"center\">Drücken Sie die Buttons in aufsteigender Richtung</p></body></html>"
        )

    def test_defaults6(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.pushButton_Neu.text(), "Neu")

    def test_defaults7(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.pushButton_End.text(), "Ende")

    def test_defaults8(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.Dialog.windowTitle(), "MyGame")

    def test_defaults9(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_4.text(), "1")

    def test_defaults10(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_0.text(), "15")

    def test_defaults11(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_1.text(), "0")

    def test_defaults12(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_2.text(), "0")

    def test_defaults13(self):
        '''Test the GUI in its default state'''
        self.assertEqual(self.controller.view.lineEdit_3.text(), "0")

    def test_defaultData1(self):
        self.assertEqual(self.controller.model.isCorrect, 0)

    def test_defaultData2(self):
        self.assertEqual(self.controller.model.isOpen, 15)

    def test_defaultData3(self):
        self.assertEqual(self.controller.model.isWrong, 0)

    def test_defaultData4(self):
        self.assertEqual(self.controller.model.isTotal, 0)

    def test_defaultData5(self):
        self.assertEqual(self.controller.model.Ngame, 1)

    def test_defaults14(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[0].text()) in range(15))

    def test_defaults15(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[1].text()) in range(15))

    def test_defaults16(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[2].text()) in range(15))
        # def test_defaults17(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[3].text()) in range(15))

    def test_defaults18(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[4].text()) in range(15))
        # def test_defaults19(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[5].text()) in range(15))

    def test_defaults20(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[6].text()) in range(15))
        # def test_defaults21(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[7].text()) in range(15))

    def test_defaults22(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[8].text()) in range(15))
        # def test_defaults23(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[9].text()) in range(15))

    def test_defaults24(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[10].text()) in range(15))
        # def test_defaults25(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[11].text()) in range(15))

    def test_defaults26(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[12].text()) in range(15))
        # def test_defaults27(self):
        #     '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[13].text()) in range(15))

    def test_defaults28(self):
        '''Test the GUI in its default state'''
        self.assertTrue(
            int(self.controller.view.buttons[14].text()) in range(15))

    def test_defaultsAllButtons(self):
        '''Test the GUI in its default state'''
        for i in range(15):
            self.assertTrue(
                int(self.controller.view.buttons[i].text()) in range(15))

    def test_isRandom(self):
        '''Test the GUI in its default state'''
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        listCompUp = [i for i in range(15)]
        #print(listCompUp)
        self.assertTrue(list0 != listCompUp)

    def test_isRandom1(self):
        '''Test the GUI in its default state'''
        list0 = [
            int(self.controller.view.buttons[i].text()) for i in range(15)
        ]
        #print(list0)
        listCompUp = [i for i in range(14, -1, -1)]
        #print(listCompUp)
        self.assertTrue(list0 != listCompUp)

    def test_isUniqueNumbers(self):
        '''Test the GUI in its default state'''
        set0 = set()
        for i in range(15):
            set0.add(int(self.controller.view.buttons[i].text()))
        #print(set0)
        self.assertTrue(len(set0) == 15)
Esempio n. 4
0
"""
Created on 17.11.2017

@author: Michael Borko <*****@*****.**>, Hans Brabenetz <*****@*****.**>
@version: 20171117

@description: Implementation eines einfachen Spiels
"""

from gamecontroller import GameController
from PyQt5 import QtCore, QtGui, QtWidgets
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    controller = GameController()
    controller.show()
    sys.exit(app.exec_())