tests/lua/staticmines.lua
author Wuzzy <almikes@aol.com>
Thu, 05 Oct 2017 05:20:25 +0200
changeset 12652 31c4a81823eb
permissions -rw-r--r--
Add test case for testing that mines don't move for a very long time
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12652
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     1
--[[ Static Mines Test
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     2
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     3
This test tests if mines are able to stand still on the ground for a very long time. 8 mines are spawned on a few girders.
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     4
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     5
The test passes if the mines don't move for a very long time.
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     6
The test failes if any mine moves even the tiniest bit or is destroyed.
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     7
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     8
This test case has been created as response to bug 96.
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
     9
]]
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    10
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    11
-- Max. time to test
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    12
local TEST_TIME_LIMIT = 3600000 * 5 -- 5 hours
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    13
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    14
local hhs = {}
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    15
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    16
function onGameInit()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    17
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    18
	ClearGameFlags()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    19
	EnableGameFlags(gfDisableWind, gfOneClanMode)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    20
	Map = ""
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    21
	Seed = 12
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    22
	Theme = "Desert"
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    23
	MapGen = mgDrawn
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    24
	TurnTime = -1
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    25
	Explosives = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    26
	MinesNum = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    27
	CaseFreq = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    28
	Delay = 100
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    29
	WaterRise = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    30
	HealthDecrease = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    31
	AirMinesNum = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    32
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    33
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    34
	AddTeam("Test Team", 0xFFFF00, "Statue", "Tank", "Default", "cm_test")
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    35
	hhs[1] = AddHog("Test Hog", 0, 100, "cm_test")
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    36
	SetGearPosition(hhs[1], 300, 1450)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    37
end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    38
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    39
local mines = {
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    40
	{ x = 231, y = 1708},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    41
	{ x = 290, y = 1708},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    42
	{ x = 342, y = 1708},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    43
	{ x = 261, y = 1708},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    44
	{ x = 319, y = 1708},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    45
	{ x = 403, y = 1706},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    46
	{ x = 428, y = 1706},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    47
	{ x = 461, y = 1706},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    48
	{ x = 498, y = 1706},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    49
	{ x = 518, y = 1706},
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    50
}
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    51
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    52
function LoadGearData()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    53
	------ GIRDER LIST ------
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    54
	PlaceGirder(290, 1718, 4)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    55
	PlaceGirder(290, 1790, 4)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    56
	PlaceGirder(452, 1716, 4)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    57
	PlaceGirder(452, 1790, 4)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    58
	
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    59
	PlaceGirder(300, 1500, 4)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    60
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    61
	------ MINE LIST ------
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    62
	for m=1, #mines do
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    63
		mines[m].gear = AddGear(mines[m].x, mines[m].y, gtMine, 0, 0, 0, 0)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    64
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    65
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    66
end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    67
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    68
function onGameStart()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    69
	LoadGearData()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    70
end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    71
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    72
function onGearDelete(gear)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    73
	for m=#mines, 1, -1 do
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    74
		if gear == mines[m] then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    75
			WriteLnToConsole(string.format("Mine %d died!", m))
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    76
			table.remove(mines, m)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    77
		end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    78
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    79
end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    80
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    81
-- Give a short time for the mines to settle first.
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    82
local checkTimer = -5000
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    83
local initPosCheck = false
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    84
-- Count the total times the mines managed to stand still
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    85
local totalTime = 0
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    86
local fin = false
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    87
function onGameTick20()
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    88
	if fin then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    89
		return
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    90
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    91
	-- Infinite turn time
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    92
	if TurnTimeLeft < 6000 then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    93
		TurnTimeLeft = -1
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    94
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    95
	checkTimer = checkTimer + 20
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    96
	if initPosCheck then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    97
		totalTime = totalTime + 20
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    98
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
    99
	if checkTimer >= 1000 then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   100
		local failed = false
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   101
		for m=1, #mines do
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   102
			if not initPosCheck then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   103
				-- Position initialization
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   104
				-- Save “real” x and y values after the mines have settled
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   105
				local x, y = GetGearPosition(mines[m].gear)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   106
				mines[m].rx = x
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   107
				mines[m].ry = y
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   108
			else
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   109
				-- Position check
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   110
				local x, y = GetGearPosition(mines[m].gear)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   111
				local rx, ry = mines[m].rx, mines[m].ry
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   112
				if not x or not y then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   113
					WriteLnToConsole(string.format("Mine %d has died!", m))
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   114
					failed = true
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   115
				elseif x ~= rx or y ~= ry then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   116
					WriteLnToConsole(string.format("Mine %d has moved! Expected: (%d, %d). Actual: (%d, %d)", m, rx, ry, x, y))
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   117
					failed = true
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   118
				end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   119
			end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   120
		end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   121
		if not initPosCheck then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   122
			initPosCheck = true
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   123
		end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   124
		if failed then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   125
			WriteLnToConsole(string.format("Test failed. The mines managed to stand still for %d ticks.", totalTime))
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   126
			EndLuaTest(TEST_FAILED)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   127
			fin = true
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   128
			return
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   129
		end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   130
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   131
	if totalTime >= TEST_TIME_LIMIT then
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   132
		WriteLnToConsole(string.format("All mines have been static for over %d ticks! Success!", TEST_TIME_LIMIT))
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   133
		EndLuaTest(TEST_SUCCESSFUL)
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   134
		fin = true
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   135
		return
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   136
	end
31c4a81823eb Add test case for testing that mines don't move for a very long time
Wuzzy <almikes@aol.com>
parents:
diff changeset
   137
end