Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit

Permalink
added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PuzzledWhale committed Apr 1, 2023
1 parent c71cbda commit cdcb147
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 129 deletions.
Binary file modified .DS_Store
Binary file not shown.
6 changes: 4 additions & 2 deletions object_log/armorplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def getBoundingBox(self) -> bb.BoundingBox:

def getLastTime(self):
self.lastTime

def setActivity(self, newAct):
self.activity = newAct

# given an armorplate we have associated in objectlog,
# add to a list of associated armor plates
Expand All @@ -74,8 +77,7 @@ def addArmorPlate(self, new_plate):
self.assoc_plates.pop()
self.assoc_plates.insert(0,new_plate)
return




def writeToHistory(self, historyFile):
# historyFile = open("pathhere",'a')
Expand Down
13 changes: 11 additions & 2 deletions object_log/objectlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
MIN_Y = -1
MIN_Z = -1

SCREEN_WIDTH = 1280
SCREEN_HEIGHT = 720


class objectlog:

def __init__(self, timestamp):
Expand Down Expand Up @@ -96,7 +100,7 @@ def boxesInput(self, boxList, currentTime):
assoc_plate.timeBuffer = 0

# bump up timer buffers and remove dead plates
kill_threshold = -1 #need to replace with an actual val
kill_threshold = 5 #need to replace with an actual val
for i in range(len(self.plates)):
p = self.plates[i]
if p.timeBuffer != 0:
Expand Down Expand Up @@ -169,15 +173,20 @@ def get_distance(self, point_one, point_two)-> float:
+np.pow((point_one[2]-point_two[2]),2))

#log all of the armor plates at the very end of the program before all the plates are deleted (genocide D:)
def kill_all(self, index):
def kill_all(self):
for plate in self.plates:
plate.setActivity(False)
plate.writeToHistory(self.objectLogOutput)
self.kill_plate(self.plates.index(plate))
self.objectLogOutput.close()
return

#logs and removes a single plate
def kill_plate(self, index):
self.plate[index].setActivity(False)
self.plates[index].writeToHistory(self.objectLogOutput)
self.plates.remove(index)

# return the center coordinates of the sreen
def getCenter(self):
return [SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2]
216 changes: 91 additions & 125 deletions object_log/test.py
Original file line number Diff line number Diff line change
@@ -1,63 +1,59 @@
from bounding_box import *
from armorplate import *

from bounding_box import *
from objectlog import *
from targetSelection import *
import numpy as np
import pytest
import time

log = objectlog(0)
# object log that persists across tests
hist_log = objectlog(0)

box = bounding_box()
armor = armorplate()

@pytest.fixture
def objectLogFixture():
return log(time.localtime(time.time()))

@pytest.fixture
def boundingBoxFixture():
return box()
num = 3
boxlistPrev = []
boxlistNext = []

@pytest.fixture
def armorplateFixture():
return armor()
dt = 1000 # time between boxListPrev and boxListNext in ms

# parameters for previous bounding boxes
# x position, y position, depth, height, width, time
prev_params = [
(100, 100, 25, 10, 10, 1),
(50, 50, 25, 10, 10, 1),
(75, 75, 25, 10, 10, 1)
(100, 100, 25, 10, 10, dt),
(50, 50, 25, 10, 10, dt),
(75, 75, 25, 10, 10, dt)
]
# parameters for next bounding boxes (next frame)
# x position, y position, depth, height, width, time
next_params = [
(101, 101, 25, 10, 10, 2*dt),
(55, 55, 25, 10, 10, 2*dt),
(76, 76, 25, 10, 10, 2*dt)
]

num = 3
boxlistPrev = []
boxlistNext = []

boxVelocities = []
boxAccelerations = []

deltaTime = 1000 # time between boxListPrev and boxListNext in ms
# bounding box VA
# x velocity, y velocity, z velocity, x acceleration, y acceleration, z acceleration
param_VA = [
(1, 1, 0, 0, 0, 0),
(5, 5, 0, 0, 0, 0),
(1, 1, 0, 0, 0, 0)
]

# create global list of bounding boxes for testing purposes
def main():
@pytest.fixture
def obj_log():
return hist_log(time.localtime(time.time()))

# generate a list of previous boxes
makeBoxes(boxlistPrev, prev_params)
@pytest.fixture
def boundingBoxFixture():
return box()

for i in range(num):
print(boxlistPrev[i].get_x_value())
print('\n')
print(boxlistPrev[i].get_y_value())
print('\n')
print(boxlistPrev[i].get_depth_value())
print('\n')
print(boxlistPrev[i].get_height_value())
print('\n')
print(boxlistPrev[i].get_width_value())
boxlistPrev[i].print_time()
print('\n')
@pytest.fixture
def armorplateFixture():
return armor()

# Hardcoding bounding boxes for temporary use
# hardcoding bounding boxes for temporary use
def makeBoxes(box_list, box_params):
for i in range(0, num):
box_list[i].append(BoundingBox())
Expand All @@ -68,110 +64,80 @@ def makeBoxes(box_list, box_params):
box_list[i].set_width_value(box_params[4])
box_list[i].set_time(box_params[5])

makeBoxes(boxlistPrev, prev_params)
makeBoxes(boxlistNext, next_params)



# Tests Needed (not comprehensize, please add more to this list as you see fit)
# Might have to test the robustness of the code later, add edge cases where needed
# X test that ID assignment is correct
# X test boxesInput (along with predicti position, assign plates and everythign in boxesInput)
# O test target selection algorithm
# X test killPlate
# X test killAllPlates

boxVelocities[0] = [-25, -25, 0]
boxAccelerations[0] = [-10, -10, 0]

boxlistNext.append(BoundingBox())
boxlistNext[0].set_x_value(75)
boxlistNext[0].set_y_value(75)
boxlistNext[0].set_depth_value(25)
boxlistNext[0].set_height_value()
boxlistNext[0].set_width_value()
boxlistNext[0].set_time()


boxVelocities[1] = [10, 20, 0]
boxAccelerations[1] = [30 ,-2, 0]

boxlistNext.append(BoundingBox())
boxlistNext[1].set_x_value()
boxlistNext[1].set_y_value()
boxlistNext[1].set_depth_value()
boxlistNext[1].set_height_value()
boxlistNext[1].set_width_value()
boxlistNext[1].set_time()


boxVelocities[2] = [40, 2, 0]
boxAccelerations[2] = [10 ,20, 0]

boxlistNext.append(BoundingBox())
boxlistNext[2].set_x_value()
boxlistNext[2].set_y_value()
boxlistNext[2].set_depth_value()
boxlistNext[2].set_height_value()
boxlistNext[2].set_width_value()
boxlistNext[2].set_time()

return


# Test something here
def test_basic(obj):
# TODO: write test
one = 1
assert one == 1
pass

def test_boxesInputInit(obj):#this doesn't test out of bounds plates yet (modify later)
log = objectlog(0)
log.boxesInput(boxlistPrev,10)
plates = log.get_plates
assert(len(plates) == 3)


#this part is to check ids (see if they are unique)
isunique = 1
for i in (0,len(plates)):
for j in range(1, len(plates)):
if isunique==1 and plates[i].getID()==plates[j].getID():
isUnique = 0

assert(isUnique==1)


log.boxesInput(boxlistNext, 10,20)
pass

# check for correct assignment of IDs to each armor plate
@pytest.mark.parametrize("expectedID", [
(0),
(1),
(2)
])

# test that ID is correctly assigned.
def test_assignID(expectedID):
log = objectlog(0) # current timestamp set to 0
log.boxesInput(boxlistPrev, 10) # 10 is random value for current time
plates = log.get_plates
hist_log.boxesInput(boxlistPrev, dt)
plates = hist_log.get_plates
for i in range(0, len(plates)):
assert plates[i].getID() == expectedID
pass

# test that bounding boxes are assigned correctly across time
# assumes that test_assign_ID has already run
def test_boxesInput():
# set the velocity and acceleration values of the existing armor plates
old_plates = hist_log.get_plates
for i in range(0, len(old_plates)):
i.updateVA(param_VA[i])

hist_log.boxesInput(boxlistNext, 2 * dt) # step forward by dt time
new_plates = hist_log.get_plates


#Should test that the object log accurately assigns plates
def test_assignPlate(obj):
plates = objectlog.get_plates
objectlog.assign_plate(boxlistPrev[0])
objectlog.assign_plate(boxlistPrev[1])
objectlog.assign_plate(boxlistPrev[2])

pass
#Should test that the object log is killing dead plates
def test_killPlate(obj):
assert len(new_plates) == 3 # if there are not 3 armor plates objects in object log, something went wrong...
for i in range(0, len(new_plates)):
assert new_plates[i].getPosition == [next_params[i][0], next_params[i][1], next_params[i][2]] #check if position of the armor plates are correct
pass

def test_killAll(obj):

# test that the camera is able to a select a target.
def test_selectTarget():
expectedTargetPosition = [next_params[0][0], next_params[0][1], next_params[0][2]] # manually set the target
target = selectTarget(hist_log, hist_log.getCenter())
assert target.getPosition == expectedTargetPosition
pass

# test that takes a plateID argument and kills a single plate
def test_killPlate(plate_ID):
plate_ID = 2 # hardcoding to remove the last element, but you can pass any plateID
plates = hist_log.get_plates
x = plates[plate_ID].getPosition[0]
y = plates[plate_ID].getPosition[1]
z = plates[plate_ID].getPosition[2]
hist_log.kill_plate(plate_ID)
for i in range(0, len(plates)): # checks the details of other plates to make sure we killed right plate
assert(i < num)
assert(x != plates[i].getPosition[0])
assert(y != plates[i].getPosition[1])
assert(z != plates[i].getPosition[2])
pass


# Test that objectlog can accurately match the right bounding box to the right armor plate after delta_t time
def test_predict(obj):
# TODO: write test
# test that checks if all plates murdered
def test_killAll():
plates = hist_log.get_plates
hist_log.kill_all
assert(len(plates) == 0) # all have died :(
pass


if __name__ == "__main__":
main()

0 comments on commit cdcb147

Please sign in to comment.