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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#
# 20,000 Light Years Into Space
# This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-21.
#
import pygame
from lib20k import game_random, map_items, network
from lib20k.ui import User_Interface
from lib20k.primitives import *
from lib20k.game_types import *
from . import unit_test
def Do_Building_Test(building: map_items.Building,
cannot_be_damaged: bool) -> None:
test_screen = unit_test.Setup_For_Unit_Test()
"""Test for map_items.py.
This tests the lifecycle of a building - construction,
upgrade, destruction. It is used to test every building type.
The buildings are drawn during testing. Though there are
some assertions here, Get_Things() is primarily intended
to produce 100% coverage."""
building.Exits()
building.Sound_Effect()
def Get_Things() -> None:
building.Get_Information()
building.Get_Diagram_Colour()
building.Get_Tech_Level()
building.Get_Health_Meter()
building.Get_Popup_Items()
building.Draw(test_screen)
building.Draw_Selected(test_screen, (255, 0, 0))
building.Draw_Popup(test_screen)
pygame.display.flip()
# construction
max_work = 1000
while building.Needs_Work():
max_work -= 1
Get_Things()
building.Do_Work()
assert not building.Is_Destroyed()
assert max_work > 0
assert not building.Is_Broken()
assert not building.Is_Destroyed()
# full health
Get_Things()
# upgrading
building.Begin_Upgrade()
while building.Needs_Work():
max_work -= 1
Get_Things()
building.Do_Work()
assert not building.Is_Destroyed()
assert max_work > 0
# upgraded
Get_Things()
if cannot_be_damaged:
return
# minor damage
building.Take_Damage()
assert not building.Is_Destroyed()
assert building.Is_Broken()
assert building.Needs_Work()
# repair
while building.Needs_Work():
max_work -= 1
Get_Things()
building.Do_Work()
assert not building.Is_Destroyed()
assert max_work > 0
assert not building.Is_Broken()
# major damage
while not building.Is_Destroyed():
max_work -= 1
building.Take_Damage()
Get_Things()
assert max_work > 0
assert building.Is_Broken()
# it's too late to do any work
assert building.Is_Destroyed()
building.Do_Work()
def test_Building() -> None:
Do_Building_Test(map_items.Building((1, 1), "foobar"), False)
def test_Node() -> None:
Do_Building_Test(map_items.Node((1, 1)), False)
def test_Well_Node() -> None:
Do_Building_Test(map_items.Well_Node((1, 1)), False)
def test_City() -> None:
Do_Building_Test(map_items.City_Node((1, 1)), True)
def test_Pipe() -> None:
demo = game_random.Game_Random(1)
net = network.Network(demo, False)
n1 = map_items.Node((1, 1))
n2 = map_items.Node((3, 3))
assert net.Add_Grid_Item(n1)
assert net.Add_Grid_Item(n2)
pipe = net.Add_Pipe(n1, n2)
assert pipe
Do_Building_Test(pipe, False)
|