Commit 5934683b29f1c12c28d19a0412d612851e82223c
1 parent
f77326a3
start adding unit tests
Showing
5 changed files
with
58 additions
and
15 deletions
Show diff stats
.gitignore
main.py
... | ... | @@ -6,22 +6,10 @@ Tf = [] #cells table |
6 | 6 | |
7 | 7 | testSample = RSSVector(-26, -42, -13, -46) |
8 | 8 | |
9 | -#cells Table initialization | |
10 | -for i in range (0, 3): | |
11 | - Tf.append([]) | |
12 | - for _ in range (0,3): | |
13 | - Tf[i].append([]) | |
14 | - | |
15 | 9 | #known fingerprints |
16 | -Tf[0][0] = newCell(-38,-27,-54,-13,2,2) | |
17 | -Tf[0][1] = newCell(-74,-62,-48,-33,2,6) | |
18 | -Tf[0][2] = newCell(-13,-28,-12,-40,2,10) | |
19 | -Tf[1][0] = newCell(-34,-27,-38,-41,6,2) | |
20 | -Tf[1][1] = newCell(-64,-48,-72,-35,6,6) | |
21 | -Tf[1][2] = newCell(-45,-37,-20,-15,6,10) | |
22 | -Tf[2][0] = newCell(-17,-50,-44,-33,10,2) | |
23 | -Tf[2][1] = newCell(-27,-28,-32,-45,10,6) | |
24 | -Tf[2][2] = newCell(-30,-20,-60,-40,10,10) | |
10 | +Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ | |
11 | + [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ | |
12 | + [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]] | |
25 | 13 | |
26 | 14 | def main(): |
27 | 15 | #### K neighbours #### | ... | ... |
structure.py
... | ... | @@ -21,6 +21,12 @@ class Location(): |
21 | 21 | self.y = y |
22 | 22 | self.z = z |
23 | 23 | |
24 | + def __eq__(self, loc2): | |
25 | + if self.x == loc2.x and self.y == loc2.y and self.z == loc2.z: | |
26 | + return True | |
27 | + else: | |
28 | + return False | |
29 | + | |
24 | 30 | def __mul__(self, multiplier): |
25 | 31 | returnValue = Location(self.x, self.y, self.z) |
26 | 32 | returnValue.x *= multiplier | ... | ... |
1 | +from structure import * | |
2 | + | |
3 | +Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ | |
4 | + [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ | |
5 | + [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]] | |
6 | + | |
7 | +testSample = RSSVector(-26, -42, -13, -46) | |
8 | +testCells = [Tf[0][2], Tf[2][1], Tf[1][0], Tf[2][0]] | |
9 | +testDistances = [34, 35, 53, 61] | |
10 | + | |
11 | + | |
12 | + | |
13 | +def test_KNeighbors(): | |
14 | + assert KNeighbors(Tf, testSample)[0].location.toString() == "(2 ; 10 ; 0)" | |
15 | + assert KNeighbors(Tf, testSample)[1].location.toString() == "(10 ; 6 ; 0)" | |
16 | + assert KNeighbors(Tf, testSample)[2].location.toString() == "(6 ; 2 ; 0)" | |
17 | + assert KNeighbors(Tf, testSample)[3].location.toString() == "(10 ; 2 ; 0)" | |
18 | + | |
19 | +def test_resolve_barycenter(): | |
20 | + | |
21 | + result = resolve_barycenter(testCells, testDistances) | |
22 | + print(testSample.distances) | |
23 | + assert round(result.x, 2) == 6.67 | |
24 | + assert round(result.y, 2) == 5.75 | |
25 | + | |
26 | +def test_Location(): | |
27 | + loc1 = Location(1,2) | |
28 | + loc2 = Location(3, 4) | |
29 | + assert loc1 + loc2 == Location(4,6) | |
30 | + assert loc1 * 2 == Location(2,4) | |
31 | + loc2 -= Location(1,1) | |
32 | + assert loc2 == Location(2,3) | |
33 | + loc1 *= 3 | |
34 | + assert loc1 == Location(3,6) | |
35 | + | |
36 | +def test_MarkovModel(): | |
37 | + test_MM = MarkovModel(Tf) | |
38 | + assert test_MM.previousCell == 0 | |
39 | + test_MM.moveToCellID(3) | |
40 | + assert test_MM.previousCell == 3 | |
41 | + test_MM.moveToCell(Tf[0][1]) | |
42 | + assert test_MM.previousCell == 2 | |
0 | 43 | \ No newline at end of file | ... | ... |