def create_large_educatives_and_seminar(cls): NUMBER_OF_KENS = 50 NUMBER_OF_EDUCATIVES = 900 NUMBER_OF_HUGS = 45 NUMBER_OF_VEGETARIAN_HUGS = 8 kens = [] for i in xrange(NUMBER_OF_KENS): ken = Ken() ken.name = "Ken " + str(i) kens.append(ken) cls.session.add(ken) educatives = [] for i in xrange(NUMBER_OF_EDUCATIVES): educative = Educative() if random.randint(0, 2) == 0: educative.gender = MALE else: educative.gender = FEMALE if random.randint(0, 9) == 0: educative.food = VEGETARIAN else: educative.food = MEAT educative.first_name = "Educative" educative.last_name = str(i) educative.ken = kens[random.randint(0, NUMBER_OF_KENS - 1)] educatives.append(educative) cls.session.add(educative) seminar = Seminar() seminar.name = 'Seminar' cls.session.add(seminar) camp1, camp2, camp3 = Camp(), Camp(), Camp() camp1.name = 'Camp 1' camp2.name = 'Camp 2' camp3.name = 'Camp3' seminar.camps += [camp1, camp2, camp3] [cls.session.add(c) for c in seminar.camps] hugs = [] for i in xrange(NUMBER_OF_HUGS): hug = Hug() hug.name = "Hug " + str(i) hug.camp = seminar.camps[i % 3] if i < NUMBER_OF_VEGETARIAN_HUGS: hug.food = VEGETARIAN hugs.append(hug) cls.session.add(hug) for j in xrange(random.randint(1, 2)): madrich = Madrich() madrich.first_name = "Madrich" madrich.last_name = str(j) madrich.ken = kens[random.randint(0, NUMBER_OF_KENS - 1)] hug.madrichim.append(madrich) cls.session.add(madrich) return educatives, seminar
def create_small_educatives_and_seminar(cls): misgav = Ken() misgav.name = 'Misgav' cls.session.add(misgav) karmiel = Ken() karmiel.name = 'Karmiel' cls.session.add(karmiel) aviad = Educative() aviad.gender = MALE aviad.first_name = "Aviad" aviad.ken = misgav cls.session.add(aviad) naama = Educative() naama.gender = FEMALE naama.first_name = "Naama" naama.ken = karmiel cls.session.add(naama) inbar = Educative() inbar.gender = FEMALE inbar.first_name = "Inbar" inbar.ken = misgav cls.session.add(inbar) alon = Educative() alon.gender = MALE alon.first_name = "Alon" alon.ken = karmiel cls.session.add(alon) seminar = Seminar() cls.session.add(seminar) camp = Camp() camp.seminar = seminar cls.session.add(camp) hug1 = Hug() hug1.name = "Hug1" hug1.camp = camp cls.session.add(hug1) hug2 = Hug() hug2.name = "Hug2" hug2.camp = camp cls.session.add(hug2) return [aviad, naama, inbar, alon], seminar
def test_madrich(self): ken = Ken() ken.name = 'Misgav' seminar = self.create_seminar(1, 1) hug = seminar.camps[0].hugs[0] aviad = Educative() aviad.first_name = 'Aviad' aviad.ken = ken aviad.hug = hug madrich = Madrich() madrich.first_name = 'Cool' madrich.last_name = 'Guy' madrich.ken = ken madrich.hug = hug constraint = MadrichHardConstraint() self.assertTrue(not constraint.is_valid(aviad, [aviad], seminar))
def test_ken_constant(self): constraint = KenRandomSoftConstraint(10, 10, 10) seminar = self.create_seminar(1, 2) hugs = seminar.camps[0].hugs ken1 = Ken() ken1.name = "A" ken2 = Ken() ken2.name = "B" second_ken = SecondKen() second_ken.name = "c" self.session.add(ken1) self.session.add(ken2) self.session.add(second_ken) educative1 = Educative() educative1.ken = ken1 educative1.hug = hugs[0] self.session.add(educative1) educative2 = Educative() educative2.ken = ken1 educative2.hug = hugs[0] self.session.add(educative2) educative3 = Educative() educative3.ken = ken1 educative3.hug = hugs[1] self.session.add(educative3) educative4 = Educative() educative4.ken = ken2 educative4.second_ken = second_ken educative4.hug = hugs[1] self.session.add(educative4) score = constraint.calculate_score([educative1, educative2, educative3, educative4], seminar) self.assertEquals(score, 70)