public void Difference() { int[] oddNumbers = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] digits = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; HashedSet <int> setOdds = new HashedSet <int>(oddNumbers); HashedSet <int> setDigits = new HashedSet <int>(digits); setOdds.ExceptWith(setDigits); int[] expectedArray1 = new int[] { 11, 13, 15, 17, 19, 21, 23, 25 }; int[] actualArray = setOdds.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray1, actualArray); setOdds = new HashedSet <int>(oddNumbers); setDigits.ExceptWith(setOdds); int[] expectedArray2 = new int[] { 2, 4, 6, 8 }; actualArray = setDigits.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray2, actualArray); setOdds.ExceptWith(setOdds); Assert.AreEqual(0, setOdds.Count); }
public void Union() { int[] oddNumbers = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] digits = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; HashedSet <int> setOdds = new HashedSet <int>(oddNumbers); HashedSet <int> setDigits = new HashedSet <int>(digits); setOdds.UnionWith(setDigits); int[] expectedArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] actualArray = setOdds.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); setOdds = new HashedSet <int>(oddNumbers); setDigits.UnionWith(setOdds); actualArray = setDigits.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); setOdds.UnionWith(setOdds); Assert.AreEqual(oddNumbers.Length, setOdds.Count); }
public void ToArray() { string[] expectedArray = { "Foo", "Eric", "Clapton", "hello", "goodbye", "C#" }; HashedSet <string> set1 = new HashedSet <string>(); string[] a1 = set1.ToArray(); Assert.IsNotNull(a1); Assert.AreEqual(0, a1.Length); foreach (string s in expectedArray) { set1.Add(s); } string[] actualArray = set1.ToArray(); Array.Sort(expectedArray); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
/// <summary> /// NHibernate configuration에서 mapping된 Assembly들을 조회한다. /// </summary> /// <param name="configuration">NHibernate Configuration 파일</param> /// <returns></returns> public static Assembly[] GetMappingAssemblies(this Configuration configuration) { configuration.ShouldNotBeNull("configuration"); var loadedAssembly = new HashedSet <Assembly>(); foreach (var persistentClass in configuration.ClassMappings) { if (log.IsDebugEnabled) { log.Debug("매핑 Assembly를 추가합니다. assembly=[{0}]", persistentClass.MappedClass.Assembly); } loadedAssembly.Add(persistentClass.MappedClass.Assembly); } return(loadedAssembly.ToArray()); }
public void SetDefaults() { DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); StringSet = new HashedSet <string> { "foo", "bar", "baz" }; StringDateMap = new SortedList(); StringDateMap.Add("now", DateTime.Now); StringDateMap.Add("never", null); // value is persisted since NH-2199 // according to SQL Server the big bag happened in 1753 ;) StringDateMap.Add("big bang", new DateTime(1753, 01, 01)); //StringDateMap.Add( "millenium", new DateTime( 2000, 01, 01 ) ); StringArray = StringSet.ToArray(); StringList = new ArrayList(StringArray); IntArray = new int[] { 1, 3, 3, 7 }; FooArray = new Foo[0]; Customs = new ArrayList(); Customs.Add(new String[] { "foo", "bar" }); Customs.Add(new String[] { "A", "B" }); Customs.Add(new String[] { "1", "2" }); FooSet = new HashedSet <FooProxy>(); Components = new FooComponent[] { new FooComponent("foo", 42, null, null), new FooComponent("bar", 88, null, new FooComponent("sub", 69, null, null)) }; TimeArray = new DateTime[] { new DateTime(), new DateTime(), new DateTime(), // H2.1 has null here, but it's illegal on .NET new DateTime(0) }; Count = 667; Name = "Bazza"; TopComponents = new ArrayList(); TopComponents.Add(new FooComponent("foo", 11, new DateTime[] { today, new DateTime(2123, 1, 1) }, null)); TopComponents.Add( new FooComponent("bar", 22, new DateTime[] { new DateTime(2007, 2, 3), new DateTime(1945, 6, 1) }, null)); TopComponents.Add(null); Bag = new ArrayList(); Bag.Add("duplicate"); Bag.Add("duplicate"); Bag.Add("duplicate"); Bag.Add("unique"); Cached = new OrderedSet <CompositeElement>(); CompositeElement ce = new CompositeElement(); ce.Foo = "foo"; ce.Bar = "bar"; CompositeElement ce2 = new CompositeElement(); ce2.Foo = "fooxxx"; ce2.Bar = "barxxx"; Cached.Add(ce); Cached.Add(ce2); CachedMap = new SortedList(); CachedMap.Add(this, ce); }
public void Difference() { int[] oddNumbers = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] digits = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; HashedSet<int> setOdds = new HashedSet<int>(oddNumbers); HashedSet<int> setDigits = new HashedSet<int>(digits); setOdds.ExceptWith(setDigits); int[] expectedArray1 = new int[] { 11, 13, 15, 17, 19, 21, 23, 25 }; int[] actualArray = setOdds.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray1, actualArray); setOdds = new HashedSet<int>(oddNumbers); setDigits.ExceptWith(setOdds); int[] expectedArray2 = new int[] { 2, 4, 6, 8 }; actualArray = setDigits.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray2, actualArray); setOdds.ExceptWith(setOdds); Assert.AreEqual(0, setOdds.Count); }
public void Union() { int[] oddNumbers = new int[] { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] digits = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; HashedSet<int> setOdds = new HashedSet<int>(oddNumbers); HashedSet<int> setDigits = new HashedSet<int>(digits); setOdds.UnionWith(setDigits); int[] expectedArray = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25 }; int[] actualArray = setOdds.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); setOdds = new HashedSet<int>(oddNumbers); setDigits.UnionWith(setOdds); actualArray = setDigits.ToArray(); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); setOdds.UnionWith(setOdds); Assert.AreEqual(oddNumbers.Length, setOdds.Count); }
public void ToArray() { string[] expectedArray = { "Foo", "Eric", "Clapton", "hello", "goodbye", "C#" }; HashedSet<string> set1 = new HashedSet<string>(); string[] a1 = set1.ToArray(); Assert.IsNotNull(a1); Assert.AreEqual(0, a1.Length); foreach (string s in expectedArray) set1.Add(s); string[] actualArray = set1.ToArray(); Array.Sort(expectedArray); Array.Sort(actualArray); CollectionAssert.AreEqual(expectedArray, actualArray); }
public IInferenceResult Ask(FOLKnowledgeBase kb, ISentence alpha) { // clauses <- the set of clauses in CNF representation of KB ^ ~alpha ISet <Clause> clauses = new HashedSet <Clause>(); foreach (Clause c in kb.GetAllClauses()) { var standardizedC = kb.StandardizeApart(c); standardizedC.SetStandardizedApartCheckNotRequired(); clauses.UnionWith(standardizedC.GetFactors()); } ISentence notAlpha = new NotSentence(alpha); // Want to use an answer literal to pull // query variables where necessary Literal answerLiteral = kb.CreateAnswerLiteral(notAlpha); ISet <Variable> answerLiteralVariables = kb .CollectAllVariables(answerLiteral.AtomicSentence); Clause answerClause = new Clause(); if (answerLiteralVariables.Count > 0) { ISentence notAlphaWithAnswer = new ConnectedSentence(Connectors.Or, notAlpha, answerLiteral.AtomicSentence); foreach (Clause c in kb.ConvertToClauses(notAlphaWithAnswer)) { var standardizedC = kb.StandardizeApart(c); standardizedC.SetProofStep(new ProofStepGoal(standardizedC)); standardizedC.SetStandardizedApartCheckNotRequired(); clauses.UnionWith(standardizedC.GetFactors()); } answerClause.AddLiteral(answerLiteral); } else { foreach (Clause c in kb.ConvertToClauses(notAlpha)) { var standardizedC = kb.StandardizeApart(c); standardizedC.SetProofStep(new ProofStepGoal(standardizedC)); standardizedC.SetStandardizedApartCheckNotRequired(); clauses.UnionWith(standardizedC.GetFactors()); } } var ansHandler = new TFMAnswerHandler(answerLiteral, answerLiteralVariables, answerClause, this.MaxQueryTime); // new <- {} ISet <Clause> newClauses = new HashedSet <Clause>(); ISet <Clause> toAdd = new HashedSet <Clause>(); // loop do int noOfPrevClauses = clauses.Count; do { if (Tracer != null) { Tracer.StepStartWhile(clauses, clauses.Count, newClauses .Count); } newClauses.Clear(); // for each Ci, Cj in clauses do Clause[] clausesA = new Clause[clauses.Count]; clausesA = clauses.ToArray(); // Basically, using the simple T)wo F)inger M)ethod here. for (int i = 0; i < clausesA.Length; i++) { Clause cI = clausesA[i]; if (null != Tracer) { Tracer.StepOuterFor(cI); } for (int j = i; j < clausesA.Length; j++) { Clause cJ = clausesA[j]; if (null != Tracer) { Tracer.StepInnerFor(cI, cJ); } // resolvent <- FOL-RESOLVE(Ci, Cj) ISet <Clause> resolvents = cI.BinaryResolvents(cJ); if (resolvents.Count > 0) { toAdd.Clear(); // new <- new <UNION> resolvent foreach (Clause rc in resolvents) { toAdd.UnionWith(rc.GetFactors()); } if (null != Tracer) { Tracer.StepResolved(cI, cJ, toAdd); } ansHandler.CheckForPossibleAnswers(toAdd); if (ansHandler.IsComplete()) { break; } newClauses.UnionWith(toAdd); } if (ansHandler.IsComplete()) { break; } } if (ansHandler.IsComplete()) { break; } } noOfPrevClauses = clauses.Count; // clauses <- clauses <UNION> new clauses.UnionWith(newClauses); if (ansHandler.IsComplete()) { break; } // if new is a <SUBSET> of clauses then finished // searching for an answer // (i.e. when they were added the # clauses // did not increase). } while (noOfPrevClauses < clauses.Count); if (null != Tracer) { Tracer.StepFinished(clauses, ansHandler); } return(ansHandler); }