Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: creating mcdc tests to valid_schedule method #225

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions api/utils/tests/test_valid_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from django.test import TestCase
from unittest.mock import Mock, patch
from utils.schedule_generator import ScheduleGenerator
from api.models import Class


class ScheduleGeneratorTestCase(TestCase):
@patch('schedules.schedule_generator.get_class_by_id')
def setUp(self, mock_get_class_by_id):
self.mock_class1 = Mock(spec=Class)
self.mock_class1.schedule = "MT123"
self.mock_class1.discipline = "Math"
self.mock_class1.id = "FGA0456"

self.mock_class2 = Mock(spec=Class)
self.mock_class2.schedule = "MT123"
self.mock_class2.discipline = "Science"
self.mock_class2.id = "FGA0123"

mock_get_class_by_id.side_effect = [self.mock_class1, self.mock_class2]

self.generator = ScheduleGenerator(
classes_id=[self.mock_class1.id, self.mock_class2.id], preference=[1, 2, 3])

def test_ct1_exception_class(self):
# CT1: Teste de saída da matéria de exceção
schedule = (self.mock_class1.id,)
except_class = self.mock_class1
result = self.generator._valid_schedule(schedule, except_class)
self.assertTrue(result)

def test_ct2_common_class(self):
# CT2: Teste de saída de matéria comum
schedule = (self.mock_class2.id,)
result = self.generator._valid_schedule(schedule)
self.assertTrue(result)

def test_ct3_same_schedule(self):
# CT3: Teste de matérias com o mesmo horário
schedule = (self.mock_class1.id, self.mock_class2.id)
except_class = None
self.generator.schedule_info[self.mock_class1.schedule]["times"] = {
('M', 'T', '1', '2', '3')}
self.generator.schedule_info[self.mock_class2.schedule]["times"] = {
('M', 'T', '1', '2', '3')}
result = self.generator._valid_schedule(schedule, except_class)
self.assertFalse(result)

def test_ct4_same_schedule_except(self):
# CT4: Teste de matérias com o mesmo horário, com uma classe de exceção
schedule = (self.mock_class1.id, self.mock_class2.id)
except_class = Mock(spec=Class)
except_class.schedule = "XYZ123"
self.generator.schedule_info[self.mock_class1.schedule]["times"] = {
('M', 'T', '1', '2', '3')}
self.generator.schedule_info[self.mock_class2.schedule]["times"] = {
('M', 'T', '1', '2', '3')}
result = self.generator._valid_schedule(schedule, except_class)
self.assertFalse(result)
Loading