Commit 8d27f825 authored by Alexander Lercher's avatar Alexander Lercher

Added integration test for similarity calculation

parent eab8c906
......@@ -4,5 +4,3 @@
*.log
**/env
**/venv
src/data-hub/role-stage-discovery-microservice/app/resultSimilarityDictN14992C221.json
......@@ -14,7 +14,6 @@ LOGGER = logging.getLogger(__name__)
#############################
import connexion
# load swagger config
app = connexion.App(__name__, specification_dir='configs/')
app.add_api('swagger.yml')
......
This source diff could not be displayed because it is too large. You can view the blob instead.
StartTime: 2020-07-07 16:55:42.418309
FinishTime: 2020-07-07 16:55:49.746628
PopulateWithNewNodes: 2.321926
CalculateWeights: 4.499367
CalculateSimilarity: 0.507026
TotalTime: 7.328319
RunId: 5f048cf587e0ee319fa894ed
\ No newline at end of file
StartTime: 2020-07-07 14:57:32.942331
FinishTime: 2020-07-07 14:57:39.489324
PopulateWithNewNodes: 2.102823
CalculateWeights: 4.382948
CalculateSimilarity: 0.061222
TotalTime: 6.546993
RunId: 5f0471438b27390711e31c70
\ No newline at end of file
......@@ -32,10 +32,6 @@ from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import *
#####TEST ONLY#####
from processing.similarityFiles.testSimilarity import *
def main():
print("\nEntered Main")
......@@ -107,9 +103,6 @@ def main():
return
def test():
testInputData()
##########START##########
#main()
test()
main()
#########FINISH##########
import unittest
import sys
sys.path.insert(1, '../')
for path in ['../', './']:
sys.path.insert(1, path)
# python -m unittest discover
from db.entities import Cluster
......
import unittest
import sys
for path in ['../', './', '../../../modules/']:
sys.path.insert(1, path)
from db.entities.connected_node import NodeC
from db.entities.connected_cluster import ClusterC
from db.entities.connected_layer import LayerC
import os
import sys
import math
import datetime
from typing import Dict
......@@ -12,63 +16,54 @@ from processing.similarityFiles.dataInput import *
from processing.similarityFiles.calculateWeights import *
from processing.similarityFiles.calculateSimilarity import *
from processing.similarityFiles.miscFunctions import *
from processing.similarityFiles.dataOutput import *
import json
import requests
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
from db.repository import *
repo = Repository()
class TestSimilarity(unittest.TestCase):
'''Tests the similarity calculation which works without object orientation.'''
def testInputData():#ONLY FOR TESTING
'''
Only for testing, can be deleted at any time.\n
Served as a testing example to make sure the computations are correct
'''
def test_integration_similarityCalculation(self):
'''
Only for testing, can be deleted at any time.\n
Served as a testing example to make sure the computations are correct
'''
limitNrNodes = 100000
limitNrNodes = 100000
layerDict = dict()
print("Creating Connected_cluster dict and similarity dict")
inputLayerLocation=getTestLocationLayerData()
inputLayerTime=getTestTimeLayerData()
inputLayerPrice=getTestPriceLayerData()
layerDict = populateWithNewNodesSingleLayer(inputLayerLocation,layerDict,limitNrNodes)
layerDict = populateWithNewNodesSingleLayer(inputLayerTime,layerDict,limitNrNodes)
layerDict = populateWithNewNodesSingleLayer(inputLayerPrice,layerDict,limitNrNodes)
layerDict = dict()
("Creating Connected_cluster dict and similarity dict")
inputLayerLocation=getTestLocationLayerData()
inputLayerTime=getTestTimeLayerData()
inputLayerPrice=getTestPriceLayerData()
layerDict = populateWithNewNodesSingleLayer(inputLayerLocation,layerDict,limitNrNodes)
layerDict = populateWithNewNodesSingleLayer(inputLayerTime,layerDict,limitNrNodes)
layerDict = populateWithNewNodesSingleLayer(inputLayerPrice,layerDict,limitNrNodes)
layerDict = calculateWeights(layerDict)
similarityDict = calculateSimilarity(layerDict)
print("Asserting if the calculated values are true")
layerDict = calculateWeights(layerDict)
similarityDict = calculateSimilarity(layerDict)
("Asserting if the calculated values are true")
#assert x == "hello"
#assert x == "hello"
# SYNTAX:
#similarityDict[(clusterLabel1,clusterLabel2,layerOfTheClusters)][layerToWhichTheClustersAreCompared] == ExpectedSimilarityValue
#checking if the cluster "1" and cluster "2" from the "Location" layer have the sqrt(2) similarity values for when compared with 'Price'and 'Time'layers
assert similarityDict[(1,2,'Location')]['Price'] == math.sqrt(2)
assert similarityDict[(1,2,'Location')]['Time'] == math.sqrt(2)
assert similarityDict[(1,3,'Location')]['Price'] == math.sqrt(10)
assert similarityDict[(1,3,'Location')]['Time'] == math.sqrt(16)
assert similarityDict[(2,3,'Location')]['Price'] == math.sqrt(4)
assert similarityDict[(2,3,'Location')]['Time'] == math.sqrt(10)
assert similarityDict[(4,5,'Time')]['Location'] == math.sqrt(19)
assert similarityDict[(4,5,'Time')]['Price'] == math.sqrt(26)
assert similarityDict[(6,7,'Price')]['Location'] == math.sqrt(3)
assert similarityDict[(6,7,'Price')]['Time'] == math.sqrt(8)
# assert similarityDict[(1,2,'Location')]
print("Test Passed Succesfully")
return layerDict
# SYNTAX:
#similarityDict[(clusterLabel1,clusterLabel2,layerOfTheClusters)][layerToWhichTheClustersAreCompared] == ExpectedSimilarityValue
#checking if the cluster "1" and cluster "2" from the "Location" layer have the sqrt(2) similarity values for when compared with 'Price'and 'Time'layers
self.assertEqual(similarityDict[(1,2,'Location')]['Price'], math.sqrt(2))
self.assertEqual(similarityDict[(1,2,'Location')]['Time'], math.sqrt(2))
self.assertEqual(similarityDict[(1,3,'Location')]['Price'], math.sqrt(10))
self.assertEqual(similarityDict[(1,3,'Location')]['Time'], math.sqrt(16))
self.assertEqual(similarityDict[(2,3,'Location')]['Price'], math.sqrt(4))
self.assertEqual(similarityDict[(2,3,'Location')]['Time'], math.sqrt(10))
self.assertEqual(similarityDict[(4,5,'Time')]['Location'], math.sqrt(19))
self.assertEqual(similarityDict[(4,5,'Time')]['Price'], math.sqrt(26))
self.assertEqual(similarityDict[(6,7,'Price')]['Location'], math.sqrt(3))
self.assertEqual(similarityDict[(6,7,'Price')]['Time'], math.sqrt(8))
# assert similarityDict[(1,2,'Location')]
("Test Passed Succesfully")
return layerDict
......@@ -402,3 +397,5 @@ def getTestPriceLayerData():
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment