diff --git a/.gitignore b/.gitignore index 0014dd6..f3ee33d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ *.pyc .vscode/ +.pytest_cache/ diff --git a/main.py b/main.py index 795faba..07ea006 100644 --- a/main.py +++ b/main.py @@ -6,22 +6,10 @@ Tf = [] #cells table testSample = RSSVector(-26, -42, -13, -46) -#cells Table initialization -for i in range (0, 3): - Tf.append([]) - for _ in range (0,3): - Tf[i].append([]) - #known fingerprints -Tf[0][0] = newCell(-38,-27,-54,-13,2,2) -Tf[0][1] = newCell(-74,-62,-48,-33,2,6) -Tf[0][2] = newCell(-13,-28,-12,-40,2,10) -Tf[1][0] = newCell(-34,-27,-38,-41,6,2) -Tf[1][1] = newCell(-64,-48,-72,-35,6,6) -Tf[1][2] = newCell(-45,-37,-20,-15,6,10) -Tf[2][0] = newCell(-17,-50,-44,-33,10,2) -Tf[2][1] = newCell(-27,-28,-32,-45,10,6) -Tf[2][2] = newCell(-30,-20,-60,-40,10,10) +Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ + [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ + [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]] def main(): #### K neighbours #### diff --git a/structure.py b/structure.py index 962191e..bbc6bee 100644 --- a/structure.py +++ b/structure.py @@ -21,6 +21,12 @@ class Location(): self.y = y self.z = z + def __eq__(self, loc2): + if self.x == loc2.x and self.y == loc2.y and self.z == loc2.z: + return True + else: + return False + def __mul__(self, multiplier): returnValue = Location(self.x, self.y, self.z) returnValue.x *= multiplier diff --git a/test_structure.py b/test_structure.py new file mode 100644 index 0000000..ea2e392 --- /dev/null +++ b/test_structure.py @@ -0,0 +1,42 @@ +from structure import * + +Tf = [[newCell(-38,-27,-54,-13,2,2),newCell(-74,-62,-48,-33,2,6),newCell(-13,-28,-12,-40,2,10) ],\ + [newCell(-34,-27,-38,-41,6,2), newCell(-64,-48,-72,-35,6,6), newCell(-45,-37,-20,-15,6,10)], \ + [newCell(-17,-50,-44,-33,10,2), newCell(-27,-28,-32,-45,10,6), newCell(-30,-20,-60,-40,10,10)]] + +testSample = RSSVector(-26, -42, -13, -46) +testCells = [Tf[0][2], Tf[2][1], Tf[1][0], Tf[2][0]] +testDistances = [34, 35, 53, 61] + + + +def test_KNeighbors(): + assert KNeighbors(Tf, testSample)[0].location.toString() == "(2 ; 10 ; 0)" + assert KNeighbors(Tf, testSample)[1].location.toString() == "(10 ; 6 ; 0)" + assert KNeighbors(Tf, testSample)[2].location.toString() == "(6 ; 2 ; 0)" + assert KNeighbors(Tf, testSample)[3].location.toString() == "(10 ; 2 ; 0)" + +def test_resolve_barycenter(): + + result = resolve_barycenter(testCells, testDistances) + print(testSample.distances) + assert round(result.x, 2) == 6.67 + assert round(result.y, 2) == 5.75 + +def test_Location(): + loc1 = Location(1,2) + loc2 = Location(3, 4) + assert loc1 + loc2 == Location(4,6) + assert loc1 * 2 == Location(2,4) + loc2 -= Location(1,1) + assert loc2 == Location(2,3) + loc1 *= 3 + assert loc1 == Location(3,6) + +def test_MarkovModel(): + test_MM = MarkovModel(Tf) + assert test_MM.previousCell == 0 + test_MM.moveToCellID(3) + assert test_MM.previousCell == 3 + test_MM.moveToCell(Tf[0][1]) + assert test_MM.previousCell == 2 \ No newline at end of file diff --git a/travis.yml b/travis.yml new file mode 100644 index 0000000..956033d --- /dev/null +++ b/travis.yml @@ -0,0 +1,6 @@ +language: python +python: + - "3.5" + - "3.6" + - "3.7" +script: pytest \ No newline at end of file -- libgit2 0.21.4