public void ConceptWithSubjectAreaCanFindIt()
        {
            // arrange
            var language        = Language.Default;
            var semanticNetwork = new TestSemanticNetwork(language);

            IList <IConcept> subjectAreas = new IConcept[]
            {
                semanticNetwork.SubjectArea_Transport,
                semanticNetwork.SubjectArea_Numbers,
                semanticNetwork.SubjectArea_Processes,
            };

            var conceptsWithoutSubjectArea = new List <IConcept>(SystemConcepts.GetAll());

            conceptsWithoutSubjectArea.AddRange(subjectAreas);

            foreach (var concept in semanticNetwork.SemanticNetwork.Concepts.Except(conceptsWithoutSubjectArea))
            {
                // act
                var answer = semanticNetwork.SemanticNetwork.Ask().ToWhichSubjectAreasBelongs(concept);

                // assert
                Assert.IsFalse(answer.IsEmpty);

                var groupStatement = (GroupStatement)answer.Explanation.Statements.Single();
                Assert.IsTrue(subjectAreas.Contains(groupStatement.Area));
                Assert.AreSame(concept, groupStatement.Concept);

                var conceptsAnswer = (ConceptsAnswer)answer;
                Assert.AreSame(groupStatement.Area, conceptsAnswer.Result.Single());
            }
        }
Ejemplo n.º 2
0
 public void OnlyLogicalValuesSuit()
 {
     foreach (var concept in SystemConcepts.GetAll())
     {
         if (!LogicalValues.All.Contains(concept))
         {
             Assert.Throws <InvalidOperationException>(() => { concept.ToBoolean(); });
             Assert.Throws <InvalidOperationException>(() => { concept.Invert(); });
         }
     }
 }
        public void SubjectAreaWithoutConceptsHasNoConcepts()
        {
            // arrange
            var language             = Language.Default;
            var semanticNetwork      = new TestSemanticNetwork(language);
            var noSubjectAreaConcept = SystemConcepts.GetAll().First();

            // act
            var answer = semanticNetwork.SemanticNetwork.Ask().WhichConceptsBelongToSubjectArea(noSubjectAreaConcept);

            // assert
            Assert.IsTrue(answer.IsEmpty);
            Assert.AreEqual(0, answer.Explanation.Statements.Count);
        }
Ejemplo n.º 4
0
        public void OnlySequenceSignsSuit()
        {
            foreach (var concept in SystemConcepts.GetAll())
            {
                if (!SequenceSigns.All.Contains(concept))
                {
                    Assert.Throws <InvalidOperationException>(() => { concept.Contradicts(SequenceSigns.SimultaneousWith); });
                    Assert.Throws <InvalidOperationException>(() => { SequenceSigns.SimultaneousWith.Contradicts(concept); });

                    Assert.Throws <InvalidOperationException>(() => { SequenceSigns.Revert(concept); });

                    Assert.Throws <InvalidOperationException>(() => { SequenceSigns.TryToCombineMutualSequences(concept, SequenceSigns.SimultaneousWith); });
                    Assert.Throws <InvalidOperationException>(() => { SequenceSigns.TryToCombineMutualSequences(SequenceSigns.SimultaneousWith, concept); });
                }
            }
        }
Ejemplo n.º 5
0
        public void OnlyComparisonSignsSuit()
        {
            foreach (var concept in SystemConcepts.GetAll())
            {
                if (!ComparisonSigns.All.Contains(concept))
                {
                    Assert.Throws <InvalidOperationException>(() => { concept.Contradicts(ComparisonSigns.IsEqualTo); });
                    Assert.Throws <InvalidOperationException>(() => { ComparisonSigns.IsEqualTo.Contradicts(concept); });

                    Assert.Throws <InvalidOperationException>(() => { ComparisonSigns.Revert(concept); });

                    Assert.Throws <InvalidOperationException>(() => { concept.CanBeReverted(); });

                    Assert.Throws <InvalidOperationException>(() => { ComparisonSigns.CompareThreeValues(concept, ComparisonSigns.IsEqualTo); });
                    Assert.Throws <InvalidOperationException>(() => { ComparisonSigns.CompareThreeValues(ComparisonSigns.IsEqualTo, concept); });
                }
            }
        }
        public void ConceptWithoutSubjectAreaHasNoSubjectArea()
        {
            // arrange
            var language                   = Language.Default;
            var semanticNetwork            = new TestSemanticNetwork(language);
            var conceptsWithoutSubjectArea = new List <IConcept>(SystemConcepts.GetAll())
            {
                semanticNetwork.SubjectArea_Transport
            };

            foreach (var concept in conceptsWithoutSubjectArea)
            {
                // act
                var answer = semanticNetwork.SemanticNetwork.Ask().ToWhichSubjectAreasBelongs(concept);

                // assert
                Assert.IsTrue(answer.IsEmpty);
                Assert.AreEqual(0, answer.Explanation.Statements.Count);
            }
        }
Ejemplo n.º 7
0
        public void CheckLargeSemanticNetworkSerialization()
        {
            // arrange
            var    language        = Language.Default;
            var    semanticNetwork = new TestSemanticNetwork(language).SemanticNetwork;
            var    name            = (LocalizedStringVariable)semanticNetwork.Name;
            var    locales         = name.Locales;
            string testFileName    = Path.GetTempFileName();

            // act
            Semantics.SemanticNetwork restored;
            try
            {
                semanticNetwork.Save(testFileName);
                restored = testFileName.LoadSemanticNetworkFromXml(language);
            }
            finally
            {
                if (File.Exists(testFileName))
                {
                    File.Delete(testFileName);
                }
            }

            // assert
            var restoredName = (LocalizedStringVariable)restored.Name;

            Assert.IsTrue(locales.SequenceEqual(restoredName.Locales));
            foreach (string locale in locales)
            {
                Assert.AreEqual(name.GetValue(locale), restoredName.GetValue(locale));
            }

            var conceptMapping = new Dictionary <IConcept, IConcept>();

            Assert.AreEqual(semanticNetwork.Concepts.Count, restored.Concepts.Count);
            foreach (var concept in semanticNetwork.Concepts /*.Except(systemConcepts)*/)
            {
                var restoredConcept = restored.Concepts.Single(c =>
                                                               c.Name.GetValue(language) == concept.Name.GetValue(language) &&
                                                               c.Hint.GetValue(language) == concept.Hint.GetValue(language));
                conceptMapping[concept] = restoredConcept;
            }

            var systemConcepts = new HashSet <IConcept>(SystemConcepts.GetAll());

            foreach (var mapping in conceptMapping)
            {
                if (systemConcepts.Contains(mapping.Key))
                {
                    Assert.AreSame(mapping.Key, mapping.Value);
                }
                else
                {
                    Assert.AreNotSame(mapping.Key, mapping.Value);
                }
            }

            Assert.AreEqual(semanticNetwork.Statements.Count, restored.Statements.Count);
            foreach (var statement in semanticNetwork.Statements)
            {
                var statementType = statement.GetType();
                var childConcepts = statement.GetChildConcepts().Select(c => conceptMapping[c]).ToList();

                // Note: check method Single() below means, that test semantic network can not contain statement duplicates.
                restored.Statements.Single(s => statementType == s.GetType() && childConcepts.SequenceEqual(s.GetChildConcepts()));
            }
        }