Example #1
0
        public void ToStringTest()
        {
            //test wish for user tostring
            Wish wish = GetSimpleWish();

            wish.WishUser = UserTests.GetSimpleUser(1);
            Assert.AreEqual("Ønsker at snakke med Bob Bobsen.", wish.ToString(), "ToString not correct for user wish");

            //test organization
            wish.WishUser         = null;
            wish.WishOrganization = new Organization("Org")
            {
                Id = 1
            };
            Assert.AreEqual("Ønsker at snakke med en person som har arbejdet i organisationen \"Org\".", wish.ToString(), "ToString not correct for organization.");
            wish.WishOrganizationTime = 1;
            Assert.AreEqual("Ønsker at snakke med en person som har arbejdet i organisationen \"Org\" i 1 år.", wish.ToString(), "ToString not correct for organization (years).");
            wish.WishOrganization = null;
            Assert.AreEqual("Ønsker at snakke med en person som har arbejdet i en organisation i 1 år.", wish.ToString(), "ToString not correct for organization time.");

            //Test interests
            wish = GetSimpleWish();
            wish.WishInterests = new List <WishInterests>()
            {
                new WishInterests(InterestTests.GetSimpleInterest(), wish)
            };
            Assert.AreEqual("Ønsker at snakke med en person som har 1 interesse.", wish.ToString(), "ToString not correct for single interest");
            wish.WishInterests.Add(new WishInterests(InterestTests.GetSimpleInterest(), wish));
            Assert.AreEqual("Ønsker at snakke med en person som har 2 interesser.", wish.ToString(), "ToString not correct for multiple interests");

            //Test businesses
            wish = GetSimpleWish();
            wish.WishBusinesses = new List <WishBusinesses>()
            {
                new WishBusinesses(BusinessTests.GetSimpleBusiness(), wish)
            };
            Assert.AreEqual("Ønsker at snakke med en person som arbejder i 1 erhverv.", wish.ToString(), "ToString not correct for single business");

            //Test wish with 2 parts
            wish.WishInterests = new List <WishInterests>()
            {
                new WishInterests(InterestTests.GetSimpleInterest(), wish)
            };
            Assert.AreEqual("Ønsker at snakke med en person som har 1 interesse og arbejder i 1 erhverv.", wish.ToString(), "ToString not correct with 2 wish parts");

            //Test wish with 3 parts
            wish.WishOrganization = new Organization("Org")
            {
                Id = 1
            };
            Assert.AreEqual("Ønsker at snakke med en person som har 1 interesse, arbejder i 1 erhverv og har arbejdet i organisationen \"Org\".", wish.ToString(), "ToString not correct with 3 wish parts");
        }
        public void CalculateHappinessScoreTest()
        {
            //Create test user
            User user = GetSimpleUser(1);

            user.UsersInterests = new List <UsersInterest>()
            {
                new UsersInterest(InterestTests.GetSimpleInterest(0), user),
                new UsersInterest(InterestTests.GetSimpleInterest(1), user),
                new UsersInterest(InterestTests.GetSimpleInterest(2), user),
                new UsersInterest(InterestTests.GetSimpleInterest(3), user),
                new UsersInterest(InterestTests.GetSimpleInterest(4), user),
                new UsersInterest(InterestTests.GetSimpleInterest(5), user)
            };
            user.UsersBusinesses = new List <UsersBusiness>()
            {
                new UsersBusiness(BusinessTests.GetSimpleBusiness(0), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(1), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(2), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(3), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(4), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(5), user)
            };

            //Create wish list
            List <Wish> wishList = new List <Wish>()
            {
                new Wish(GetSimpleUser(), EventTests.GetSimpleEvent(), 10)
                {
                    WishUser = GetSimpleUser(1)
                }
            };

            wishList.Add(WishTests.GetSimpleWish());
            wishList[1].WishInterests = new List <WishInterests>()
            {
                new WishInterests(InterestTests.GetSimpleInterest(0), wishList[1]),
                new WishInterests(InterestTests.GetSimpleInterest(1), wishList[1]),
                new WishInterests(InterestTests.GetSimpleInterest(2), wishList[1]),
                new WishInterests(InterestTests.GetSimpleInterest(3), wishList[1]),
                new WishInterests(InterestTests.GetSimpleInterest(4), wishList[1]),
                new WishInterests(InterestTests.GetSimpleInterest(5), wishList[1])
            };
            Assert.AreEqual(1000, user.CalculateHappinessScore(wishList), "Happiness score was supposed to be the highest score of all the wishes.");
        }
        public void SortTest()
        {
            //Create test users
            Event @event    = EventTests.GetSimpleEvent(0);
            User  testUser1 = UserTests.GetSimpleUser(1);
            User  testUser2 = UserTests.GetSimpleUser(2);
            User  testUser3 = UserTests.GetSimpleUser(3);
            User  testUser4 = UserTests.GetSimpleUser(4);

            testUser1.Wishes = new List <Wish>()
            {
                new Wish(testUser1, @event, 10)
                {
                    WishUser = testUser2
                },
                new Wish(testUser1, @event, 10)
                {
                    WishUser = testUser4
                }
            };
            testUser1.UsersInterests = new List <UsersInterest>()
            {
                new UsersInterest(InterestTests.GetSimpleInterest(0), testUser1)
            };
            testUser2.Wishes = new List <Wish>()
            {
                new Wish(testUser2, @event, 10)
                {
                    WishUser = testUser1
                }
            };
            testUser3.Wishes = new List <Wish>()
            {
                new Wish(testUser3, @event, 10)
                {
                    WishInterests = new List <WishInterests>()
                    {
                        new WishInterests(InterestTests.GetSimpleInterest(), WishTests.GetSimpleWish())
                    }
                }
            };
            testUser4.Wishes = new List <Wish>()
            {
                new Wish(testUser4, @event, 10)
                {
                    WishUser = testUser1
                }
            };
            testUser1.Invites.Add(new Invite(@event, testUser1, new DateTime(2000, 10, 9)));
            testUser2.Invites.Add(new Invite(@event, testUser2, new DateTime(2000, 10, 9)));
            testUser3.Invites.Add(new Invite(@event, testUser3, new DateTime(2000, 10, 10)));
            testUser4.Invites.Add(new Invite(@event, testUser4, new DateTime(2000, 10, 12)));

            //test meetings
            Assert.ThrowsException <ArgumentNullException>(() => { MeetingScore.Sort(null, new MeetingScore(0, testUser1, testUser2)); });
            Assert.ThrowsException <ArgumentNullException>(() => { MeetingScore.Sort(new MeetingScore(0, testUser1, testUser2), null); });

            //Create test meeting scores
            MeetingScore testMeeting1 = new MeetingScore(@event.Id, testUser1, testUser2);
            MeetingScore testMeeting2 = new MeetingScore(@event.Id, testUser2, testUser1);
            MeetingScore testMeeting3 = new MeetingScore(@event.Id, testUser3, testUser1);
            MeetingScore testMeeting4 = new MeetingScore(@event.Id, testUser4, testUser1);

            //do tests
            Assert.AreEqual(0, MeetingScore.Sort(testMeeting1, testMeeting2));
            Assert.AreEqual(-1, MeetingScore.Sort(testMeeting1, testMeeting3));
            Assert.AreEqual(1, MeetingScore.Sort(testMeeting3, testMeeting1));
            Assert.AreEqual(-1, MeetingScore.Sort(testMeeting1, testMeeting4));
            Assert.AreEqual(1, MeetingScore.Sort(testMeeting4, testMeeting1));
        }
        public void CalculateHappinessScoreTest1()
        {
            //Create test user
            User user = GetSimpleUser(1);

            user.UsersInterests = new List <UsersInterest>()
            {
                new UsersInterest(InterestTests.GetSimpleInterest(0), user),
                new UsersInterest(InterestTests.GetSimpleInterest(1), user),
                new UsersInterest(InterestTests.GetSimpleInterest(2), user),
                new UsersInterest(InterestTests.GetSimpleInterest(3), user),
                new UsersInterest(InterestTests.GetSimpleInterest(4), user),
                new UsersInterest(InterestTests.GetSimpleInterest(5), user)
            };
            user.UsersBusinesses = new List <UsersBusiness>()
            {
                new UsersBusiness(BusinessTests.GetSimpleBusiness(0), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(1), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(2), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(3), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(4), user),
                new UsersBusiness(BusinessTests.GetSimpleBusiness(5), user)
            };

            //Test if 100% interest wish gives correct score
            Wish wish = WishTests.GetSimpleWish();

            wish.WishInterests = new List <WishInterests>()
            {
                new WishInterests(InterestTests.GetSimpleInterest(0), wish),
                new WishInterests(InterestTests.GetSimpleInterest(1), wish),
                new WishInterests(InterestTests.GetSimpleInterest(2), wish),
                new WishInterests(InterestTests.GetSimpleInterest(3), wish),
                new WishInterests(InterestTests.GetSimpleInterest(4), wish),
                new WishInterests(InterestTests.GetSimpleInterest(5), wish)
            };
            Assert.AreEqual(700, user.CalculateHappinessScore(wish), "Happiness score got the wrong result");

            //Test if 50% interest/business gives correct score
            wish = new Wish(GetSimpleUser(), EventTests.GetSimpleEvent(), 10)
            {
                WishInterests = new List <WishInterests>()
                {
                    new WishInterests(InterestTests.GetSimpleInterest(0), wish),
                    new WishInterests(InterestTests.GetSimpleInterest(1), wish),
                    new WishInterests(InterestTests.GetSimpleInterest(2), wish)
                },
                WishBusinesses = new List <WishBusinesses>()
                {
                    new WishBusinesses(BusinessTests.GetSimpleBusiness(0), wish),
                    new WishBusinesses(BusinessTests.GetSimpleBusiness(1), wish),
                    new WishBusinesses(BusinessTests.GetSimpleBusiness(2), wish),
                    new WishBusinesses(BusinessTests.GetSimpleBusiness(101), wish)
                }
            };
            //business score = 600/725
            //interest score = 725/725
            Assert.AreEqual(639, user.CalculateHappinessScore(wish), "Happiness score was not supposed to be 700");

            //Test if user wishes outputs correct score
            wish = new Wish(GetSimpleUser(), EventTests.GetSimpleEvent(), 10)
            {
                WishUser = GetSimpleUser(1)
            };
            Assert.AreEqual(1000, user.CalculateHappinessScore(wish), "Happiness score was not supposed to be 1000 because it was a user wish");
        }