def test_getTask_cascade(self):
        subject = TaskBagCollection([
            TaskBag(1, 0, 0, 0, []),
            TaskBag(1, 0, 0, 0, [Task("6a"), Task("6b")]),
            TaskBag(0, 1, 1, 0, [])
        ], Random(1))

        self.assertEqual("6b,6a", subject.get_task())
    def test_getTask_manyLevels_manyTasks(self):
        subject = TaskBagCollection([
            TaskBag(2, 0, 0, 0, [Task("3a"), Task("3b")]),
            TaskBag(0, 0, 0, 0, [Task("3c"), Task("3d")])
        ], Random(3))

        self.assertEqual("3b", subject.get_task())
        self.assertEqual("3c", subject.get_task())
        self.assertEqual("3d", subject.get_task())
        self.assertEqual("3a", subject.get_task())
    def test_getTask_shuffle(self):
        subject = TaskBagCollection([TaskBag(0, 0, 0, 1, [Task("6a", 3)])],
                                    Random(1))

        subject.get_task()
        subject.get_task()

        remainingTasks = 0
        for level in subject.get_tasks():
            for task in level.tasks:
                remainingTasks += task.remaining
        self.assertEqual(2, remainingTasks)
    def test_getTask_noDrawsRemaining(self):
        # Should reset the remaining amount on each task before drawing another one

        subject = TaskBagCollection([
            TaskBag(1, 0, 0, 0, [Task("5a", 2)]),
            TaskBag(0, 0, 0, 0, [Task("5b")])
        ], Random(1))

        self.assertEqual("5a", subject.get_task())
        self.assertEqual("5a", subject.get_task())
        self.assertEqual("5b", subject.get_task())
        self.assertEqual("5a", subject.get_task())
Esempio n. 5
0
    def parse(filepath: str) -> TaskBagCollection:
        returnValue: TaskBagCollection = TaskBagCollection()
        file = open(filepath)
        csv_reader = csv.reader(file, delimiter=',')

        next_line_control = True
        for row in csv_reader:
            if len(row) == 0:
                next_line_control = True
                continue

            if next_line_control:
                next_line_control = False
                returnValue.levels.append(
                    TaskBag(int(row[0]), int(row[2]), int(row[1]),
                            int(row[3])))
            else:
                returnValue.levels[-1].tasks.append(
                    Task(row[2], int(row[1]), int(row[0])))

        file.close()
        return returnValue
    def test_getTask_oneLevel_oneTask(self):
        subject = TaskBagCollection([TaskBag(0, 0, 0, 0, [Task("1")])])

        self.assertEqual("1", subject.get_task())
    def test_getTask_multipleDraws(self):
        subject = TaskBagCollection([TaskBag(0, 0, 0, 0, [Task("4a", 2)])])

        self.assertEqual("4a", subject.get_task())
        self.assertEqual("4a", subject.get_task())
    def test_getTask_oneLevel_manyTasks(self):
        subject = TaskBagCollection(
            [TaskBag(0, 0, 0, 0, [Task("2a"), Task("2b")])], Random(1))

        self.assertEqual("2a", subject.get_task())
        self.assertEqual("2b", subject.get_task())
Esempio n. 9
0
import unittest
import os
from filecmp import cmp
from helpers.FileIO import FileIO
from domain.TaskBagCollection import TaskBagCollection
from domain.TaskBag import TaskBag
from domain.Task import Task

test_file_location = './temp.csv'
output_file_location = './actual.csv'
test_collection = TaskBagCollection([
    TaskBag(1, 0, 0, 0, [Task('Hello', 1), Task('World', 2)]),
    TaskBag(0, 1, 1, 1,
            [Task('Foo', 3, 0), Task('Bar', 4, 3)])
])


class TestFileIO(unittest.TestCase):
    def setUp(self) -> None:
        os.system('cp ../../example_files/happypath.csv.backup %s' %
                  test_file_location)

    def tearDown(self) -> None:
        os.system('rm %s' % test_file_location)
        os.system('rm %s' % output_file_location)

    def test_parse(self):
        actual: TaskBagCollection = FileIO.parse(test_file_location)

        self.assertEqual(test_collection, actual)