Esempio n. 1
0
        public void KnowledgeTest_OccupationAndRelationship_AnswerReturned()
        {
            //Who was married to Queen Meve?
            //The King of Temeria
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            var meve = testCharacter.MyMemory.Persons.FindPersonByName("Meve");

            //ASSERT
            Assert.IsNotNull(meve);

            var husband = meve.FindRelationshipsByType(PersonalRelationshipType.Family).FirstOrDefault(r => r.Description == "wife-of")?.RelatedPerson;

            Assert.IsNotNull(husband);

            var occupation = husband.GetCurrentOccupation();

            Assert.IsNotNull(occupation);
            Assert.AreEqual("King of Temeria", occupation.Name);
        }
Esempio n. 2
0
        public void Hibernate_CronosInstanceWithFollowersAndKnowledge_FileWritten()
        {
            //ARRANGE
            OmniscienceFileController controller = new OmniscienceFileController();

            Cronos.Instance.FileController = controller;
            Cronos.Instance.DeactivateMemoryBackups();
            if (controller.FileExists())
            {
                controller.DeleteFile();
            }

            var referenceData = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            for (int i = 0; i < 50; i++)
            {
                Person newPerson = new Person("NPC" + i, Gender.Agender, Sex.Undefined, Orientation.Asexual, Guid.Empty);
                var    newNpc    = new global::RNPC.Core.Character(newPerson, Archetype.None);

                foreach (var data in referenceData)
                {
                    if (RandomValueGenerator.GeneratePercentileIntegerValue() < 34)
                    {
                        newNpc.AddContentToLongTermMemory(data);
                    }
                }
                Cronos.Instance.AddFollower(newNpc);
            }

            Cronos.Instance.AddReferenceDataList(referenceData);
            //ACT
            Cronos.Instance.Hibernate();
            //ASSERT
            Assert.IsTrue(controller.FileExists());
        }
Esempio n. 3
0
        public void WriteToFile_PerformanceTests_StatisticsReturned()
        {
            //ARRANGE
            MemoryFileController myController = new MemoryFileController(Directory.GetCurrentDirectory());//Cronos.Instance.BackupMemoryFiles);

            var knowledge     = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());
            var testCharacter = CreateTestCharacter(knowledge);

            for (int i = 0; i <= 5; i++)
            {
                if (i > 0)
                {
                    testCharacter.AddContentToLongTermMemory(knowledge);
                }

                for (int k = 1; k <= 10; k++)
                {
                    Stopwatch timer = new Stopwatch();

                    timer.Start();
                    SerializeAndEncryptData(testCharacter);
                    timer.Stop();

                    Debug.Write((i + 1) + "\t" + timer.ElapsedMilliseconds);

                    timer.Restart();
                    DeserializeAndDecryptData(testCharacter);
                    timer.Stop();
                    Debug.Write("\t" + timer.ElapsedMilliseconds + "\r");

                    myController.DeleteFile(testCharacter.UniqueId);
                }
            }
        }
Esempio n. 4
0
        public void KnowledgeTest_TheNorthernWars_AnswerReturned()
        {
            //What battle did Geralt fight in?
            //Geralt fought in the battle against Nilfgaard
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            // ReSharper disable once InconsistentNaming
            var Geralt = testCharacter.MyMemory.Persons.FindPersonByName("Geralt");

            //ASSERT
            Assert.IsNotNull(Geralt);

            var eventsInvolved = Geralt.FindLinkedEventsByInvolvementType(PersonalInvolvementType.FoughtIn);

            Assert.IsNotNull(eventsInvolved);
            Assert.IsTrue(eventsInvolved.Count != 0);
            Assert.AreEqual("The Northern  Wars", eventsInvolved[0].Name);
        }
Esempio n. 5
0
        public void KnowledgeTest_TheConjunction_AnswerReturned()
        {
            //Where was the Conjunction of the Spheres?
            //The Continent saw the Conjunction of the Spheres
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            var theConjuction = testCharacter.MyMemory.Events.FindEventByName("Conjunction");

            //ASSERT
            Assert.IsNotNull(theConjuction);

            var continent = theConjuction.FindLinkedPlaceByOccurenceType(OccurenceType.HappenedIn);

            Assert.IsNotNull(continent);
            Assert.AreEqual("The Continent", continent.Name);
        }
Esempio n. 6
0
        public void KnowledgeTest_OccupationAndOrigin_AnswerReturned()
        {
            //Where do Vikings come from?
            //from Skellige
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            var vikings = testCharacter.MyMemory.Occupations.FindOccupationByName("Vikings");

            //ASSERT
            Assert.IsNotNull(vikings);

            Place vikingOrigin = vikings.FindLinkedPlaceByType(OccupationalTieType.OriginatedFrom);

            Assert.IsNotNull(vikingOrigin);
            Assert.IsTrue(vikingOrigin.Name.Contains("Skellige"));
        }
Esempio n. 7
0
        public void KnowledgeTest_ConquestOfRedania_AnswerReturned()
        {
            //Who conquered Redania?
            //The Emperor of Nilfgaard conquered Redania
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            // ReSharper disable once InconsistentNaming
            var Redania = testCharacter.MyMemory.Places.FindPlaceByName("Redania");

            //ASSERT
            Assert.IsNotNull(Redania);

            var theConquest = Redania.FindLinkedEventByType(OccurenceType.Conquest);

            Assert.IsNotNull(theConquest);

            var leader = theConquest.FindOccupationsByInvolvementType(OccupationalInvolvementType.Led);

            Assert.IsNotNull(leader);
            Assert.IsTrue(leader.Count == 1);
            Assert.AreEqual("Imperator", leader[0].Name);
            Debug.Write($"The {leader[0].Name} of the {leader[0].FindLinkedPlaceByType(OccupationalTieType.Led)} led the {theConquest.Name}");
        }
Esempio n. 8
0
        public void WriteToFile_MemoriesWithContent_MemoriesWrittenToFile()
        {
            //ARRANGE
            MemoryFileController myController = new MemoryFileController(Directory.GetCurrentDirectory());
            List <MemoryItem>    knowledge    = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var testCharacter = CreateTestCharacter(knowledge);

            //ACT
            myController.WriteToFile(testCharacter.UniqueId, testCharacter.MyMemory);

            //Assert
            myController.FileExists(testCharacter.UniqueId);

            //Cleanup
            myController.DeleteFile(testCharacter.UniqueId);
        }
Esempio n. 9
0
        public void New_WithInitializedMemory_MemoryContentSet()
        {
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var testCharacter = GetMeSterlingArcher();

            testCharacter.AddContentToLongTermMemory(knowledge);

            testCharacter.MyMemory.GetMyInformation().Description = "Sterling is a secret agent for ISIS";

            Assert.IsTrue(testCharacter.MyMemory.HowManyThingsDoIknow() > 0);
            Assert.IsTrue(testCharacter.MyMemory.HowManyThingsDoIknow() < 77);
            Assert.IsTrue(testCharacter.MyMemory.GetMyInformation().ItemType == MemoryItemType.Person);
            //TODO
            Assert.AreNotEqual(string.Empty, testCharacter.MyMemory.GetMyInformation().Description);
            //Assert.IsTrue(testCharacter.MyMemory.Persons.DoIKnowThisPerson(new Person("Geralt of Rivia")));
        }
Esempio n. 10
0
        public void WriteToFile_MemoriesWithContent_MemoriesReadFromile()
        {
            //ARRANGE
            MemoryFileController myController = new MemoryFileController(Directory.GetCurrentDirectory());

            var testCharacter = CreateTestCharacter(MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory()));

            myController.WriteToFile(testCharacter.UniqueId, testCharacter.MyMemory);

            Stopwatch perfTime = new Stopwatch();

            perfTime.Start();

            //ACT
            var memory = myController.ReadFromFile(testCharacter.UniqueId);

            perfTime.Stop();
            Debug.Write("Time spent: " + perfTime.ElapsedMilliseconds);

            //Assert
            Assert.IsNotNull(memory);
            Assert.AreEqual(77, memory.HowManyThingsDoIknow());

            var knowledge = memory.WhatDoIKnow();

            Assert.IsTrue(knowledge[0].ItemType == MemoryItemType.Person);
            Assert.IsTrue(knowledge[1].ItemType == MemoryItemType.Person);
            Assert.IsTrue(knowledge[7].ItemType == MemoryItemType.PastEvent);
            Assert.IsTrue(knowledge[9].ItemType == MemoryItemType.PastEvent);
            Assert.IsTrue(knowledge[16].ItemType == MemoryItemType.Place);
            Assert.IsTrue(knowledge[21].ItemType == MemoryItemType.Place);
            Assert.IsTrue(knowledge[27].ItemType == MemoryItemType.Organization);
            Assert.IsTrue(knowledge[32].ItemType == MemoryItemType.Occupation);
            Assert.IsTrue(knowledge[39].ItemType == MemoryItemType.PersonalRelationship);
            Assert.IsTrue(knowledge[40].ItemType == MemoryItemType.Association);
            Assert.IsTrue(knowledge[46].ItemType == MemoryItemType.EventRelationship);
            Assert.IsTrue(knowledge[51].ItemType == MemoryItemType.PersonalTie);
            Assert.IsTrue(knowledge[54].ItemType == MemoryItemType.PlaceRelationship);
            Assert.IsTrue(knowledge[57].ItemType == MemoryItemType.OccupationalTie);

            //Cleanup
            myController.DeleteFile(testCharacter.UniqueId);
        }
        public void WriteToFile_OmniscienceFile_FileWritten()
        {
            //ARRANGE
            OmniscienceFileController controller = new OmniscienceFileController();

            if (controller.FileExists())
            {
                controller.DeleteFile();
            }

            var referenceData = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());
            Dictionary <Guid, MemoryItem> dataDictionary = new Dictionary <Guid, MemoryItem>();

            foreach (var item in referenceData)
            {
                dataDictionary.Add(Guid.NewGuid(), item);
            }

            Omniscience allKnowledge = new Omniscience(dataDictionary);

            for (int i = 0; i < 50; i++)
            {
                Person newPerson = new Person("NPC" + i, Gender.Agender, Sex.Undefined, Orientation.Asexual, Guid.Empty);
                var    newNpc    = new global::RNPC.Core.Character(newPerson, Archetype.None);

                for (int j = 0; j < referenceData.Count; j++)
                {
                    if (RandomValueGenerator.GeneratePercentileIntegerValue() < 34)
                    {
                        newNpc.AddContentToLongTermMemory(dataDictionary.ElementAt(j).Value);
                    }
                }

                allKnowledge.AddFollower(newNpc);
            }
            //ACT
            controller.WriteToFile(allKnowledge);
            //ASSERT
            controller.FileExists();
        }
Esempio n. 12
0
        public void KnowledgeTest_BattleOfCintra_AnswerReturned()
        {
            //Who conquered Cintra?
            //Nilfgaard conquered Cintra at the battle of Cintra
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            // ReSharper disable once InconsistentNaming
            var Cintra = testCharacter.MyMemory.Places.FindPlaceByName("Cintra");

            //ASSERT
            Assert.IsNotNull(Cintra);

            var conquest = Cintra.FindLinkedEventByType(OccurenceType.Conquest);

            Assert.IsNotNull(conquest);

            var conqueringKing = conquest.FindOccupationsByInvolvementType(OccupationalInvolvementType.Led);

            Assert.IsNull(conqueringKing);

            var emperator = Cintra.FindOccupationsByOccupationalTieType(OccupationalTieType.Conquered);

            Assert.IsNotNull(emperator);
            Assert.IsTrue(emperator.Count == 1);
            Assert.AreEqual("Imperator", emperator[0].Name);
        }
Esempio n. 13
0
        public void KnowledgeTest_FoundationOfAKingdom_AnswerReturned()
        {
            // When was Aedirn founded
            // in 813
            //ARRANGE
            var knowledge = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory());

            var guineaPig = new Person("Guinea Pig", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(guineaPig, Archetype.None, knowledge)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                KnowledgeRandomizer = new TestKnowledgeRandomization()
            };

            testCharacter.AddContentToLongTermMemory(knowledge);
            //ACT
            var dateOfFoundation = testCharacter.MyMemory.Places.WhenWasThisPlaceFounded("Aedirn");

            //ASSERT
            Assert.IsNotNull(dateOfFoundation);
            Assert.AreEqual(813, dateOfFoundation[0].GetYear());
        }