create test folder, and simple tests

This commit is contained in:
unknown 2023-11-28 18:37:43 +01:00
parent bbbf32728b
commit 3f8ab806e6
5 changed files with 311225 additions and 8 deletions

View File

Can't render this file because it is too large.

161155
testy/ (1).json Normal file

File diff suppressed because it is too large Load Diff

149948
testy/ (2).json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,17 +1,47 @@
import csv
import random
import unittest
from unittest import mock
def modelAndVisTest:
#Wiersze ze zbioru:
# Test sprawdzający czy funkcja wyciąga właściwe ustawienie z pliku
wiersz_1 = [0,Right Center Forward,Open Play,Blocked,Normal,"[97.0, 48.0]","[113.0, 38.0]",none,none,none,none,none,none,none,none,"[112.0, 28.0]","[103.0, 50.0]","[120.0, 26.0]","[109.0, 39.0]","[117.0, 31.0]","[115.0, 41.0]","[113.0, 32.0]","[115.0, 36.0]",none,[],0]
wiersz_3 = [5,Center Midfield,Open Play,Blocked,Half Volley,"[96.0, 38.0]","[113.0, 42.0]","[107.0, 38.0]","[105.0, 40.0]","[103.0, 52.0]","[103.0, 34.0]",none,none,none,none,"[111.0, 44.0]","[109.0, 35.0]","[106.0, 44.0]","[104.0, 37.0]","[119.0, 40.0]","[113.0, 39.0]","[104.0, 52.0]","[114.0, 45.0]","[102.0, 46.0]",[],0]
wiersz_5 = [5,Right Center Back,Open Play,Goal,Normal,"[103.0, 36.0]","[97.0, 45.0]","[97.0, 52.0]","[112.0, 39.0]","[112.0, 44.0]","[98.0, 34.0]",none,none,none,none,"[114.0, 46.0]","[107.0, 37.0]","[111.0, 33.0]","[110.0, 32.0]","[111.0, 35.0]","[111.0, 38.0]","[119.0, 38.0]","[105.0, 50.0]","[107.0, 41.0]",[],0]
def GainPossition(n,file):
ret = ""
with open(file, newline='') as f:
reader = csv.reader(f)
for i in range(1,n):
ret = next(reader)
return ret
class modelAndVisTest(unittest.TestCase):
def modelAndVisTest(self):
#Wiersze ze zbioru:
# Test sprawdzający czy funkcja wyciąga właściwe ustawienie z pliku
file = "test_dataSet.csv"
wiersz_1_5 = [113.0, 38.0]
wiersz_1_2 = "Right Center Forward"
wiersz_7_3 = "Open Play"
wiersz_23_4 = "Off T"
# Pobranie pozycji za pomocą testowanej funkcji
p_wiersz_1 = GainPossition(1,file)
p_wiersz_7 = GainPossition(7,file)
p_wiersz_23 = GainPossition(23,file)
self.assertEquals(wiersz_1_5,p_wiersz_1[5])
self.assertEquals(wiersz_1_2,p_wiersz_1[2])
self.assertEquals(wiersz_7_3,p_wiersz_1[3])
self.assertEquals(wiersz_23_4,p_wiersz_1[4])
unittest.main()

84
testy/dataVisTest.py Normal file
View File

@ -0,0 +1,84 @@
import csv
import unittest
from unittest import mock
import json
import os
def openGameFile(name):
path = os.path.join(name)
f = open(path)
data = json.load(f)
return data
def uploadData(inputFile, outputFile, nadpisz):
try:
jsonFile = openGameFile(inputFile)
clean_event = []
for event in jsonFile:
if(event["type"]["name"]=="Shot"):
clean_event = []
#time
clean_event.append(event["minute"])
#location
clean_event.append(event["position"]["name"])
# shot type
clean_event.append(event["shot"]["type"]["name"])
#outcome
clean_event.append(event["shot"]["outcome"]["name"])
clean_event.append(event["shot"]["technique"]["name"])
m_players = []
en_players = []
keeper = []
for player in event["shot"]["freeze_frame"]:
player_p = 0
if player["teammate"] :
m_players.append(player["location"])
elif player["position"] == 'Goalkeeper':
keeper = player['location']
else:
en_players.append(player["location"])
for i in range(0,10):
if(len(m_players)>i):
clean_event.append(m_players[i])
else:
clean_event.append("none")
for i in range(0,9):
if(len(en_players)> i):
clean_event.append(en_players[i])
else:
clean_event.append("none")
clean_event.append(keeper)
if(event["shot"]["outcome"]=="Goal"):
clean_event.append(1)
else:
clean_event.append(0)
#Saving to a file
with open(outputFile, 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow(clean_event)
except:
raise Exception("invalid data")
class modelAndVisTest(unittest.TestCase):
def dataCleaningTest(self):
# 1().json - Dane w dobrym Formacie
# 2().json - błedne dane
uploadData("(1).json", "test_1", True)
with self.assertRaises(Exception):
uploadData("(2).json", "test_2", True)
unittest.main()