forked from mhoek2/pycalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_application.py
63 lines (49 loc) · 2.09 KB
/
test_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import sys
import pygame
from pygame.sprite import Group
from pygame.time import Clock
# app core modules
from modules.app.settings import Settings
from modules.app.renderer import Renderer
# app specific modules
from modules.gui.gui import Gui
from modules.calculator import Calculator
from modules.notes import Notes
from modules.koppelcode import KoppelCode
# testing
import pytest
from main import Application
@pytest.fixture
def app_instance():
app = Application()
#app.m_gui.openTab( app.m_gui.TAB_CALCULATOR )
#app.run()
return app
def test_module_instances( app_instance ):
"""Test if modules are set and match the correct class data type"""
assert isinstance( app_instance.m_settings, Settings )
assert isinstance( app_instance.m_clock, Clock )
assert isinstance( app_instance.m_renderer, Renderer )
# app specific modules
assert isinstance( app_instance.m_gui, Gui )
assert isinstance( app_instance.m_notes, Notes )
assert isinstance( app_instance.m_koppelcode, KoppelCode )
assert isinstance( app_instance.m_calculator, Calculator )
def test_koppelcode( app_instance ):
"""Test if koppelcode returns string and correct amount of letters"""
num_letters = 6
# generate koppelcode
code = app_instance.m_koppelcode.get_random_code( num_letters )
print( f"code generated: {code}" )
# check if generator code is a string
assert isinstance( code, str )
# check if number of letter matches the requested amount of letters
assert( len(code) == num_letters )
def test_calculator( app_instance ):
"""Test calculator methods"""
assert( app_instance.m_calculator.parse_equation_string( "1+1" ) == 2 )
assert( app_instance.m_calculator.parse_equation_string( "2*2" ) == 4 )
assert( app_instance.m_calculator.parse_equation_string( "4/2" ) == 2 )
assert( app_instance.m_calculator.parse_equation_string( "2-1" ) == 1 )
assert( app_instance.m_calculator.parse_equation_string( "0.1+0.1" ) == 0.2 )
assert( app_instance.m_calculator.parse_equation_string( "100-0.05" ) == 99.95 )