Exemplo n.º 1
0
 def test_josephus_append(self):
     self.ring.people.append(Person("jeona", 12))
     assert self.ring.people == [
         Person("Lisa", 13),
         Person("Aha", 15),
         Person("jeona", 12)
     ]
Exemplo n.º 2
0
 def test_josephus_next(self):
     self.ring.start = 1
     self.ring.step = 2
     result1 = next(self.ring)
     result2 = next(self.ring)
     assert result1 == Person("Aha", 15)
     assert result2 == Person("Lisa", 13)
Exemplo n.º 3
0
def test_interface_check_start_value():
    interface = Interface()
    interface.strat = 3
    interface.create_josephus()
    interface.people = [Person('Bob', 12), Person('Jack', 11)]

    with pytest.raises(ValueError):
        interface.check_strat_value()
Exemplo n.º 4
0
def test_interface_create_people_from_text():
    text = "Jack, 12\nBob, 11\nTony, 14"
    interface = Interface()
    people = interface.create_people_from_text(text)

    assert people[0] == Person('Jack', 12)
    assert people[1] == Person('Bob', 11)
    assert people[2] == Person('Tony', 14)
Exemplo n.º 5
0
def test_interface_get_result():
    people = [Person('Bob', 12), Person('Jack', 11)]
    interface = Interface()
    interface.reader = people
    interface.create_josephus()
    result = interface.get_result()

    assert result == "elimination Bob, 12\nwinner\tJack, 11\n"
Exemplo n.º 6
0
def test_josephus_next(people_data):
    jos = josephus.JosephusRing()
    jos.start = 1
    jos.step = 2
    jos.people = people_data
    result1 = next(jos)
    result2 = next(jos)
    assert result1 == Person("lisa", 11)
    assert result2 == Person("lily", 12)
Exemplo n.º 7
0
def test_josephus_output_order_by_next(people_example):
    jos = Josephus()
    jos.start = 2
    jos.step = 2
    jos.people = people_example

    assert next(jos) == Person('Peter', 14)
    assert next(jos) == Person('Jack', 13)
    assert next(jos) == Person('Bob', 12)
    with pytest.raises(StopIteration):
        next(jos)
Exemplo n.º 8
0
def test_josephus_query_list(people_example):
    jos = Josephus()
    jos.start = 2
    jos.step = 2
    jos.people = people_example
    result = jos.query_list()

    assert result == [
        Person('Peter', 14),
        Person('Jack', 13),
        Person('Bob', 12)
    ]
Exemplo n.º 9
0
def test_josephus_init_with_reader(people_example):
    reader = mock.MagicMock()
    reader.__iter__.return_value = people_example
    jos = Josephus(reader)

    reader.__iter__.assert_called_with()
    assert jos.start == 1
    assert jos.step == 1
    assert jos.people == [
        Person('Bob', 12),
        Person('Jack', 13),
        Person('Peter', 14)
    ]
Exemplo n.º 10
0
 def add_person(self):
     print("please input name and age of participant")
     go_on = 1
     while go_on:
         person = Person()
         person.name = input('please input name of participant: ')
         try:
             person.age = int(input('please input age of participant: '))
         except ValueError:
             print('invalid value of age, please input again')
             self.add_person()
             return
         self.josephus.append(person)
         go_on = int(
             input(
                 "please select whether to continue to input\n1: YES\t0: NO\n"
             ))
Exemplo n.º 11
0
 def __next__(self):
     item = next(self.csv_reader)
     name = item[0]
     try:
         age = int(item[1])
         if age < 0:
             age = 0
     except ValueError:
         age = 0
     return Person(name, age)
Exemplo n.º 12
0
 def people_data(self):
     return [
         Person("Lisa", 13),
         Person("Aha", 15),
         Person("Bob", 12),
         Person("Cindy", 15),
         Person("Joan", 14),
         Person("Rose", 19),
     ]
Exemplo n.º 13
0
    def __next__(self):
        row = next(self.file)
        if not row:
            raise StopIteration

        row_ = row.strip()
        item = row_.split(',')
        name = item[0]
        try:
            age = int(item[1])
            if age < 0:
                age = 0
        except ValueError:
            age = 0
        return Person(name, age)
Exemplo n.º 14
0
 def create_people_from_text(self, text: str) -> list:
     if text:
         people = []
         text = text.strip()
         persons_info = text.split('\n')
         for item in persons_info:
             info = item.split(',')
             name = info[0]
             try:
                 age = int(info[1])
             except ValueError:
                 age = 0
             people.append(Person(name, age))
         return people
     else:
         return []
Exemplo n.º 15
0
def test_csv_reader():
    csv_reader = CSVReader('data/person.csv')
    result: List[Person] = []
    for each in csv_reader:
        result.append(each)

    assert result == [
        Person('Bob', 15),
        Person('Jack', 12),
        Person('Allen', 17),
        Person('Tony', 20),
        Person('Peter', 15),
        Person('Rose', 16),
        Person('Wade', 19)
    ]
Exemplo n.º 16
0
def test_txt_reader():
    txt_reader = TxtReader("data/person.txt")
    result: List[Person] = []
    for each in txt_reader:
        result.append(each)

    assert result == [
        Person('Bob', 15),
        Person('Jack', 12),
        Person('Allen', 17),
        Person('Tony', 20),
        Person('Peter', 15),
        Person('Rose', 16),
        Person('Wade', 19)
    ]
Exemplo n.º 17
0
def test_txt_reader_from_zip_file():
    txt_reader = TxtReader.from_zip('data/person.zip', 'person.txt')
    result: List[Person] = []
    for each in txt_reader:
        result.append(each)

    assert result == [
        Person('Bob', 15),
        Person('Jack', 12),
        Person('Allen', 17),
        Person('Tony', 20),
        Person('Peter', 15),
        Person('Rose', 16),
        Person('Wade', 19)
    ]
Exemplo n.º 18
0
def test_interface_create_csvreader_from_zip():
    interface = Interface()
    interface.create_reader("data/person.zip", "person.csv")
    result: list = []
    for each in interface.reader:
        result.append(each)

    assert result == [
        Person('Bob', 15),
        Person('Jack', 12),
        Person('Allen', 17),
        Person('Tony', 20),
        Person('Peter', 15),
        Person('Rose', 16),
        Person('Wade', 19)
    ]
Exemplo n.º 19
0
def test_interface_create_josephus():
    interface = Interface()
    interface.reader = TxtReader("data/person.txt")
    interface.start = 2
    interface.step = 3
    interface.create_josephus()

    assert interface.josephus.start == 2
    assert interface.josephus.step == 3
    assert interface.josephus.people == [
        Person('Bob', 15),
        Person('Jack', 12),
        Person('Allen', 17),
        Person('Tony', 20),
        Person('Peter', 15),
        Person('Rose', 16),
        Person('Wade', 19)
    ]
Exemplo n.º 20
0
 def test_joseph_pop_(self):
     self.ring.pop(0)
     assert self.ring.people == [Person("Aha", 15)]
Exemplo n.º 21
0
def test_josephus_append(people_data):
    person1 = Person("lily", 12)
    jos = josephus.JosephusRing()
    jos.people.append(person1)
    assert jos.people == [person1]
Exemplo n.º 22
0
def test_josephus_pop(people_example):
    jos = Josephus()
    jos.people = people_example
    jos.pop(1)

    assert jos.people == [Person('Bob', 12), Person('Peter', 14)]
Exemplo n.º 23
0
def test_josephus_append():
    someone1: Person = Person('Bob', 12)
    jos = Josephus()
    jos.append(someone1)

    assert jos.people == [someone1]
Exemplo n.º 24
0
def test_joseph_pop(people_data):
    jos = josephus.JosephusRing()
    jos.people = people_data
    jos.pop(0)
    assert jos.people == [Person("lisa", 11)]
Exemplo n.º 25
0
def people_example():
    return [Person('Bob', 12), Person('Jack', 13), Person('Peter', 14)]
Exemplo n.º 26
0
 def test_josephus_init(self):
     assert self.ring.start == 0
     assert self.ring.step == 0
     assert self.ring.people == [Person("Lisa", 13), Person("Aha", 15)]
Exemplo n.º 27
0
 def test_josephus_query_list(self):
     person = self.ring.query_list()
     assert person == [Person("Lisa", 13), Person("Aha", 15)]
Exemplo n.º 28
0
def people_data():
    return [Person("lily", 12), Person("lisa", 11)]
Exemplo n.º 29
0
 def setUp(self):
     mock = MagicMock()
     mock.__iter__.return_value = [Person("Lisa", 13), Person("Aha", 15)]
     self.ring = JosephusRing(mock)
Exemplo n.º 30
0
def test_interface_get_people_info():
    people = [Person('Bob', 12), Person('Jack', 11)]
    interface = Interface()
    info = interface.get_people_info(people)

    assert info == 'Bob, 12\nJack, 11\n'