You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.0 KiB
78 lines
2.0 KiB
import pytest
|
|
from utils import *
|
|
import importlib
|
|
import sys
|
|
|
|
class Test_Cents:
|
|
def test_zeros(self):
|
|
assert cents("0") == 0
|
|
assert cents("0.") == 0
|
|
assert cents("00.") == 0
|
|
assert cents("00") == 0
|
|
assert cents("0.0") == 0
|
|
assert cents("00.0") == 0
|
|
assert cents("0.00") == 0
|
|
assert cents("00.00") == 0
|
|
assert cents(".0") == 0
|
|
assert cents(".00") == 0
|
|
|
|
def test_less_than_dollar(self):
|
|
assert cents("0.99") == 99
|
|
assert cents("0.9") == 90
|
|
assert cents("0.90") == 90
|
|
assert cents("0.02") == 2
|
|
assert cents(".99") == 99
|
|
assert cents(".9") == 90
|
|
assert cents(".90") == 90
|
|
assert cents(".02") == 2
|
|
|
|
def test_integral(self):
|
|
assert cents("1") == 100
|
|
assert cents("3") == 300
|
|
assert cents("25") == 2500
|
|
assert cents("2.0") == 200
|
|
assert cents("2.") == 200
|
|
assert cents("12.") == 1200
|
|
assert cents("2.00") == 200
|
|
|
|
def test_more_than_dollar(self):
|
|
assert cents("2.99") == 299
|
|
assert cents("2.90") == 290
|
|
assert cents("2.9") == 290
|
|
assert cents("1.75") == 175
|
|
assert cents("64.75") == 6475
|
|
assert cents("64.05") == 6405
|
|
assert cents("64.1") == 6410
|
|
|
|
class Test_Demo:
|
|
def reload(self):
|
|
global DEMO
|
|
importlib.reload(sys.modules['utils'])
|
|
from utils import DEMO
|
|
|
|
def test_empty(self):
|
|
sys.argv = ["name.py"]
|
|
self.reload()
|
|
assert DEMO == False
|
|
|
|
def test_bad(self):
|
|
sys.argv = ["name.py", "gmainus"]
|
|
self.reload()
|
|
assert DEMO == False
|
|
|
|
def test_good(self):
|
|
sys.argv = ["name.py", "demo"]
|
|
self.reload()
|
|
assert DEMO == True
|
|
|
|
def test_mult_bad(self):
|
|
sys.argv = ["name.py", "gmainus", "hdemo"]
|
|
self.reload()
|
|
assert DEMO == False
|
|
|
|
def test_mult_good(self):
|
|
sys.argv = ["name.py", "stupid", "demo"]
|
|
self.reload()
|
|
assert DEMO == True
|
|
|