140 lines
4.1 KiB
Python
140 lines
4.1 KiB
Python
from django.test import TestCase
|
|
from jarvis.objective.models import Skill, TouchPosition
|
|
from jarvis.objective.tools import (
|
|
nb_skill_by_type,
|
|
nb_skill_lte_type,
|
|
compute_completude,
|
|
compute_statistics_by_type,
|
|
)
|
|
|
|
|
|
class ToolsTestCase(TestCase):
|
|
def setUp(self):
|
|
""" """
|
|
departure_and_landing, _ = TouchPosition.objects.get_or_create(
|
|
long_label="debout", short_label="debout"
|
|
)
|
|
|
|
skill_1 = Skill.objects.create(
|
|
long_label="1/2 vrille",
|
|
difficulty=0.1,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=1,
|
|
rank=1,
|
|
)
|
|
skill_3 = Skill.objects.create(
|
|
long_label="4 pattes",
|
|
difficulty=0.1,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=1,
|
|
rank=1,
|
|
)
|
|
skill_2 = Skill.objects.create(
|
|
long_label="tour",
|
|
difficulty=0.2,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=2,
|
|
rank=2,
|
|
)
|
|
skill_4 = Skill.objects.create(
|
|
long_label="Ventre",
|
|
difficulty=0.1,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=2,
|
|
rank=2,
|
|
)
|
|
skill_5 = Skill.objects.create(
|
|
long_label="3/4 Avant /",
|
|
difficulty=0.3,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=3,
|
|
rank=3,
|
|
)
|
|
skill_6 = Skill.objects.create(
|
|
long_label="Avant /",
|
|
difficulty=0.6,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=3,
|
|
rank=3,
|
|
)
|
|
skill_7 = Skill.objects.create(
|
|
long_label="Barani /",
|
|
difficulty=0.6,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=4,
|
|
rank=4,
|
|
)
|
|
skill_8 = Skill.objects.create(
|
|
long_label="3/4 Avant vrille",
|
|
difficulty=0.5,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=4,
|
|
rank=4,
|
|
)
|
|
skill_9 = Skill.objects.create(
|
|
long_label="Rudy",
|
|
difficulty=0.8,
|
|
departure=departure_and_landing,
|
|
landing=departure_and_landing,
|
|
position="0",
|
|
rotation_type="0",
|
|
rotation="0",
|
|
twist="1",
|
|
level=4,
|
|
rank=4,
|
|
)
|
|
|
|
def test_nb_skill_lte_type(self):
|
|
# Cas "None"
|
|
self.assertEqual(nb_skill_lte_type(2, "unkown_string"), None)
|
|
# Cas normal
|
|
self.assertEqual(nb_skill_lte_type(2, "level"), 4)
|
|
self.assertEqual(nb_skill_lte_type(2, "rank"), 4)
|
|
self.assertEqual(nb_skill_lte_type(4, "level"), 9)
|
|
|
|
def test_compute_completude(self):
|
|
self.assertEqual(compute_completude(10, 1, 4), ("10%", 0))
|
|
self.assertEqual(compute_completude(10, 1, 4), ("10%", 0))
|
|
self.assertEqual(compute_completude(10, 5, 4), ("50%", 2))
|
|
self.assertEqual(compute_completude(10, 10, 4), ("100%", 4))
|