public async Task ManyHouseCats() { var tom = Literal.NewAtom(); var heathcliff = Literal.NewAtom(); var sylvester = Literal.NewAtom(); var houseCat = Literal.NewFunctor(1); var any = Literal.NewVariable(); var knowledge = KnowledgeBase.New() .Assert(Clause.Always(houseCat.With(tom))) .Assert(Clause.Always(houseCat.With(heathcliff))) .Assert(Clause.Always(houseCat.With(sylvester))); // Get all the cats var solver = new SimpleDispatchingSolver(); await solver.LoadFromKnowledgeBase(knowledge); var allResults = new List<ILiteral>(); for (var result = solver.Query(houseCat.With(any)); result != null && result.Success; result = await result.Next()) { allResults.Add(result.Bindings.GetValueForVariable(any)); } Assert.IsTrue(allResults.Contains(tom)); Assert.IsTrue(allResults.Contains(heathcliff)); Assert.IsTrue(allResults.Contains(sylvester)); Assert.AreEqual(3, allResults.Count); }
[Ignore ("not up to date")] // X509Chain public void DefaultValues () { X509Chain chain = new X509Chain (); chain.Build (cert); Assert.IsTrue (chain.ChainElements.Count > 1, "#0"); ClaimSet cs = new X509CertificateClaimSet (cert); ClaimSet ident = cs.Issuer; X509CertificateClaimSet x509is = ident as X509CertificateClaimSet; Assert.IsNotNull (x509is, "#0-2"); Assert.AreEqual (chain.ChainElements [1].Certificate, x509is.X509Certificate, "#0-3"); Assert.AreEqual (6, cs.Count, "#1"); Assert.AreEqual (6, ident.Issuer.Count, "#2"); Assert.IsFalse (cs.ContainsClaim (Claim.System), "#3"); List<string> d = new List<string> (); foreach (Claim c in cs) { if (c.ClaimType != ClaimTypes.Thumbprint) Assert.AreEqual (Rights.PossessProperty, c.Right, "#4"); d.Add (c.ClaimType); } Assert.IsTrue (d.Contains (ClaimTypes.X500DistinguishedName), "#5"); Assert.IsTrue (d.Contains (ClaimTypes.Thumbprint), "#6"); Assert.IsTrue (d.Contains (ClaimTypes.Dns), "#7"); Assert.IsTrue (d.Contains (ClaimTypes.Rsa), "#8"); Assert.IsTrue (d.Contains (ClaimTypes.Name), "#9"); }
public void DcAwareNeverHitsRemoteDc() { var builder = Cluster.Builder().WithLoadBalancingPolicy(new DCAwareRoundRobinPolicy("dc1")); //create a cluster with 2 nodes on dc1 and another 2 nodes on dc2 var clusterInfo = TestUtils.CcmSetup(2, builder, null, 2); try { var session = clusterInfo.Session; var hosts = new List<IPAddress>(); for (var i = 0; i < 50; i++) { var rs = session.Execute("SELECT * FROM system.schema_columnfamilies"); hosts.Add(rs.Info.QueriedHost); } //Only the ones in the local Assert.True(hosts.Contains(IPAddress.Parse(IpPrefix + "1")), "Only hosts from the local DC should be queried 1"); Assert.True(hosts.Contains(IPAddress.Parse(IpPrefix + "2")), "Only hosts from the local DC should be queried 2"); Assert.False(hosts.Contains(IPAddress.Parse(IpPrefix + "3")), "Only hosts from the local DC should be queried 3"); Assert.False(hosts.Contains(IPAddress.Parse(IpPrefix + "4")), "Only hosts from the local DC should be queried 4"); } finally { TestUtils.CcmRemove(clusterInfo); } }
public void TestRandomness() { IPAddress[] ips = new IPAddress[4]; for (byte i = 0; i < ips.Length; ++i) { ips[i] = new IPAddress(new byte[] {192, 168, 0, i}); } IEndpointStrategy endpointStrategy = ServiceActivator<Factory>.Create<IEndpointStrategy>("Random", ips.AsEnumerable()); List<IPAddress> alls = new List<IPAddress>(); for (int i = 0; i < 10000; ++i) { IPAddress nextEndpoint = endpointStrategy.Pick(null); if (! alls.Contains(nextEndpoint)) { alls.Add(nextEndpoint); } } foreach (IPAddress ip in alls) { Assert.IsTrue(alls.Contains(ip)); } }
public void ShouldReturnCorrectWinnerCombo() { var checker = new VerticalWinnerChecker(); var winningCombo = new List<DiscPosition>(); var playerDiscs = new List<DiscPosition>() { new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 1}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 4}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 5}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 6}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 7}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 1, Y = 8}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 10, Y = 10} }; var result = checker.IsWinner(playerDiscs, out winningCombo); Assert.IsTrue(winningCombo.Contains(playerDiscs[1])); Assert.IsTrue(winningCombo.Contains(playerDiscs[2])); Assert.IsTrue(winningCombo.Contains(playerDiscs[3])); Assert.IsTrue(winningCombo.Contains(playerDiscs[4])); Assert.IsTrue(winningCombo.Contains(playerDiscs[5])); Assert.IsTrue(winningCombo.Count == 5); }
public void UserInfo_add_remove_resources() { UserInfo userInfo = new UserInfo(1, "wicked"); int resourcesChanged = 0; userInfo.ResourcesChanged += delegate { resourcesChanged++; }; userInfo.AddResource(1, "0"); Assert.AreEqual(1, resourcesChanged); Assert.AreEqual(1, userInfo.Resources.Length); Assert.AreEqual(1, userInfo.Resources[0].Item1); userInfo.AddResource(2, "0"); userInfo.AddResource(3, "0"); userInfo.AddResource(4, "0"); Assert.AreEqual(4, resourcesChanged); Assert.AreEqual(4, userInfo.Resources.Length); List<uint> resources = new List<uint>(); foreach(Tuplet<uint, string> tuple in userInfo.Resources) { resources.Add(tuple.Item1); } Assert.IsTrue(resources.Contains(2)); userInfo.RemoveResource(2); Assert.AreEqual(5, resourcesChanged); Assert.AreEqual(3, userInfo.Resources.Length); resources.Clear(); foreach(Tuplet<uint, string> tuple in userInfo.Resources) { resources.Add(tuple.Item1); } Assert.IsFalse(resources.Contains(2)); }
public void FindAmicableNumbersUnderTenThousand() { const long limit = 10000; var list = new List<long>(); for (long l = 1; l < limit; ++l) { if (list.Contains(l)) continue; var amicable = GetAmicablePair(l); if (amicable != 0 && amicable < limit) { list.Add(l); if (!list.Contains(amicable)) list.Add(amicable); } } foreach (var l in list) { Console.WriteLine(l); } var result = list.Sum(); Console.WriteLine("Sum of amicable numbers is: {0}", result); result.Should().Be(31626); }
public void SqliteInitializationTest() { string dbPath = Path.Combine(PCLStorage.FileSystem.Current.LocalStorage.Path, DB_FILE_NAME); using (SQLiteLocalStorage storage = new SQLiteLocalStorage()) { } using (SQLiteConnection connection = new SQLiteConnection(dbPath)) { var query = "SELECT name FROM sqlite_master WHERE type='table'"; var tableName = new List<string>(); using (var sqliteStatement = connection.Prepare(query)) { while(sqliteStatement.Step() == SQLiteResult.ROW) { tableName.Add(sqliteStatement.GetText(0)); } } Assert.IsTrue(tableName.Count == 2); Assert.IsTrue(tableName.Contains("datasets")); Assert.IsTrue(tableName.Contains("records")); } }
public static void States(Accessible accessible, params StateType [] expected) { List <StateType> expectedStates = new List <StateType> (expected); List <StateType> missingStates = new List <StateType> (); List <StateType> superfluousStates = new List <StateType> (); StateSet stateSet = accessible.StateSet; foreach (StateType state in Enum.GetValues (typeof (StateType))) { if (expectedStates.Contains (state) && (!(stateSet.Contains (state)))) missingStates.Add (state); else if ((!expectedStates.Contains (state)) && (stateSet.Contains (state))) superfluousStates.Add (state); } string missingStatesMsg = string.Empty; string superfluousStatesMsg = string.Empty; if (missingStates.Count != 0) { missingStatesMsg = "Missing states: "; foreach (StateType state in missingStates) missingStatesMsg += state.ToString () + ","; } if (superfluousStates.Count != 0) { superfluousStatesMsg = "Superfluous states: "; foreach (StateType state in superfluousStates) superfluousStatesMsg += state.ToString () + ","; } Assert.IsTrue ((missingStates.Count == 0) && (superfluousStates.Count == 0), missingStatesMsg + " .. " + superfluousStatesMsg); }
public void TestGetAll() { List<TestObj> testObjs = new List<TestObj>(); for (int i = 0; i < 10; i++) { testObjs.Add(new TestObj(i.ToString(), i)); } var records = database.SaveAll(testObjs); foreach (var record in records) { Assert.IsTrue(testObjs.Contains(record.Value), "IObjectDatabase.SaveAll failed"); } records = database.GetAll<TestObj>(); foreach (var record in records) { Assert.IsTrue(testObjs.Contains(record.Value), "IObjectDatabase.GetAll failed to return an object from memory"); } database.Dispose(); database = new SQLiteObjectDatabase(databaseFile); var newRecords = database.GetAll<TestObj>(); foreach (var record in records) { Assert.IsTrue(records.FirstOrDefault(i => newRecords.Select(g => g.UniqueId).Contains(i.UniqueId)) != null, "IObjectDatabase.GetAll failed to return an object from storage"); } }
public void GetLargestGroups() { var d = new Dictionary<string, int>(); for (int i = 0; i < _strings.Length; i++) { int old; d.TryGetValue(_strings[i], out old); d[_strings[i]] = old + _values[i]; } for (int i = 0; i < _strings.Length; i++) { Assert.AreEqual(_values[i], d[_strings[i]]); } var largest = new List<KeyValuePair<string, int>> {new KeyValuePair<string, int>("None", 0)}; int max = 0; // Iterate and find maximum values. foreach (var kvp in d) { if (kvp.Value > max) { largest.Clear(); max = kvp.Value; } if (kvp.Value == max) largest.Add(kvp); } Assert.AreEqual(2, largest.Count); Assert.IsTrue(largest.Contains(new KeyValuePair<string, int>("b", 42))); Assert.IsTrue(largest.Contains(new KeyValuePair<string, int>("d", 42))); }
public void ShouldReturnCorrectWinnerCombo() { var checker = new RightToLeftDiagonalChecker(); var winningCombo = new List<DiscPosition>(); var playerDiscs = new List<DiscPosition> { new DiscPosition(){ PlayerInitialLetter = 'T', X = 4, Y = 2}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 8, Y = 10}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 9, Y = 9}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 10, Y = 8}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 11, Y = 7}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 12, Y = 6}, new DiscPosition(){ PlayerInitialLetter = 'T', X = 15, Y = 15} }; var result = checker.IsWinner(playerDiscs, out winningCombo); Assert.IsTrue(winningCombo.Contains(playerDiscs[1])); Assert.IsTrue(winningCombo.Contains(playerDiscs[2])); Assert.IsTrue(winningCombo.Contains(playerDiscs[3])); Assert.IsTrue(winningCombo.Contains(playerDiscs[4])); Assert.IsTrue(winningCombo.Contains(playerDiscs[5])); Assert.IsTrue(winningCombo.Count == 5); }
public void Simple() { var hashList = new HashList<int, string> {{2, "a"}}; Assert.AreEqual(hashList.ValueCount, 1); Assert.AreEqual(hashList.KeyCount, 1); hashList.Add(4, new List<string>(new[] { "2", "3", "4", "5" })); Assert.AreEqual(hashList.ValueCount, 5); Assert.AreEqual(hashList.KeyCount, 2); var enumerator = hashList.GetValueEnumerator(); var list = new List<string>(); while (enumerator.MoveNext()) { list.Add(enumerator.Current); } Assert.AreEqual(list.Count, 5); Assert.IsTrue(list.Contains("a")); Assert.IsTrue(list.Contains("2")); Assert.IsTrue(list.Contains("3")); Assert.IsTrue(list.Contains("4")); Assert.IsTrue(list.Contains("5")); }
public void MaxSize() { IKernel kernel = new DefaultKernel(); kernel.Register(Component.For(typeof(PoolableComponent1)).Named("a")); var instances = new List<PoolableComponent1> { kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a"), kernel.Resolve<PoolableComponent1>("a") }; PoolableComponent1 other1 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(other1); Assert.IsTrue(!instances.Contains(other1)); foreach (PoolableComponent1 inst in instances) { kernel.ReleaseComponent(inst); } kernel.ReleaseComponent(other1); PoolableComponent1 other2 = kernel.Resolve<PoolableComponent1>("a"); Assert.IsNotNull(other2); Assert.IsTrue(other1 != other2); Assert.IsTrue(instances.Contains(other2)); kernel.ReleaseComponent(other2); }
public void Contains_WithPredicate() { var testList = new List<string> { "One", "Two", "Three" }; Assert.That(testList.Contains(s => s.StartsWith("T")), Is.True); Assert.That(testList.Contains(s => s.StartsWith("Z")), Is.False); }
private static void CheckIfTablesExist(SqlConnection connection) { var command = new SqlCommand("SELECT TABLE_NAME FROM information_schema.tables", connection); var tables = new List<string>(); using (SqlDataReader reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { var table = reader.GetString(0); tables.Add(table); } reader.Close(); } } Assert.GreaterOrEqual(tables.Count, 5); Assert.IsTrue(tables.Contains("VersionInfo")); Assert.IsTrue(tables.Contains("TestItems")); Assert.IsTrue(tables.Contains("TestItemCategories")); Assert.IsTrue(tables.Contains("TestItemChildren")); Assert.IsTrue(tables.Contains("InheritedTestItems")); }
public void ShouldProvideCurrentItems() { var window = LaunchPetShopWindow(); var listBox = window.Find<ListBox>("petRulesInput"); var items = new List<string>(listBox.Items); Assert.True(items.Contains("Rule[Dangerous]")); Assert.True(items.Contains("Rule[No Children]")); }
public void ThenIGetAListOfAllTheRolesAssignedToTheUser() { var roleList = new List<string>(userRoles); Assert.IsTrue(roleList.Contains("admin")); Assert.IsTrue(roleList.Contains("webuser")); Assert.IsTrue(roleList.Count == 2); }
public void ShouldProvideCurrentItems() { Window window = LaunchPetShopWindow(); ComboBox comboBox = window.Find<ComboBox>("petFoodInput"); var items = new List<string>(comboBox.Items); Assert.True(items.Contains("PetFood[Carnivorous]")); Assert.True(items.Contains("PetFood[Eats People]")); }
public void KeepTopPeptideFromSameEngineDifferentParameters() { List<IIdentifiedSpectrum> spectra = new List<IIdentifiedSpectrum>(new IIdentifiedSpectrum[] { s1, s2, s4, s5 }); IdentifiedSpectrumUtils.KeepTopPeptideFromSameEngineDifferentParameters(spectra, new ScoreFunction()); Assert.AreEqual(2, spectra.Count); Assert.IsTrue(spectra.Contains(s1)); Assert.IsTrue(spectra.Contains(s4)); }
public void TestAllMechanisms() { var mechanisms = new List<string>(SaslMechanisms.AllMechanisms); Assert.Greater(mechanisms.Count, 0); Assert.IsTrue(mechanisms.Contains(SaslMechanisms.Anonymous)); Assert.IsTrue(mechanisms.Contains(SaslMechanisms.DigestMD5)); }
public void VerifyAssertions() { List<int> list = new List<int>(); list.Add(_instanceOne.InvokeMethod()); list.Add(_instanceTwo.InvokeMethod()); Assert.AreEqual(2, list.Count); Assert.IsTrue(list.Contains(1)); Assert.IsTrue(list.Contains(2)); }
public void ShouldProvideSubMenus() { _window = LaunchPetShopWindow(); var menu = _window.Find<Menu>("mainMenu"); var subMenu = menu.Find<Menu>("tabMenu"); var items = new List<string>(subMenu.Items); Assert.True(items.Contains("TabPresenter[History]")); Assert.True(items.Contains("TabPresenter[Accessories]")); }
public void VerifyAssertions() { List<int> list = new List<int>(); list.Add(_instanceOne.Accept(_visitor)); list.Add(_instanceTwo.Accept(_visitor)); Assert.AreEqual(2, list.Count); Assert.IsTrue(list.Contains(1)); Assert.IsTrue(list.Contains(2)); }
public void ContainsTest() { var series = new List<double> {1, 2, 3, 4}.ToSeries(); Assert.IsTrue(series.Contains(3)); Assert.IsFalse(series.Contains(5)); var untypedSeries = (Series) series; Assert.IsTrue(untypedSeries.Contains(3)); Assert.IsFalse(untypedSeries.Contains(10)); }
public void KeepUnconflictPeptidesFromSameEngineDifferentParameters() { List<IIdentifiedSpectrum> spectra = new List<IIdentifiedSpectrum>(new IIdentifiedSpectrum[] { s1, s2, s6, s7 }); IdentifiedSpectrumUtils.KeepUnconflictPeptidesFromSameEngineDifferentParameters(spectra, new ScoreFunction()); Assert.AreEqual(3, spectra.Count); Assert.IsTrue(spectra.Contains(s1)); Assert.IsTrue(spectra.Contains(s6)); Assert.IsTrue(spectra.Contains(s7)); }
public void then_added_elements_to_existing_list_are_added() { List<string> list = new List<string> {"three"}; list.AddRange(new[] { "one", "two" }); Assert.AreEqual(3, list.Count); Assert.IsTrue(list.Contains("one")); Assert.IsTrue(list.Contains("two")); Assert.IsTrue(list.Contains("three")); }
public void Can_find_files_in_batch() { var storage = CreateStorage(); storage.Put("batch1", "file1", "content1"); storage.Put("batch1", "file2", "content2"); storage.Put("batch2", "file3", "content3"); var list = new List<string>( storage.GetAllFilesInBatch("batch1")); Assert.AreEqual(2,list.Count); Assert.IsTrue(list.Contains("file1")); Assert.IsTrue(list.Contains("file2")); }
public void TestSample() { var test = new List<string>() { "One", "Two", "Three", "four", "test" }; List<string> list = (List<string>)test.Sample(3); Assert.AreEqual(3, list.Count); Assert.AreEqual(true, test.Contains(list[0])); Assert.AreEqual(true, test.Contains(list[1])); Assert.AreEqual(true, test.Contains(list[2])); }
private bool CheckOrderA(List<string> callList) { return callList.Contains("mod2") && callList.Contains("mod3") && callList.Contains("mod4") && callList.Contains("mod5") && callList.Contains("mod25") && callList.IndexOf("mod3") < callList.IndexOf("mod4") && callList.IndexOf("mod5") > callList.IndexOf("mod4") && callList.IndexOf("mod25") > callList.IndexOf("mod2") && callList.IndexOf("mod25") < callList.IndexOf("mod3") && callList.IndexOf("mod25") < callList.IndexOf("mod4") && callList.IndexOf("mod2.x") < callList.IndexOf("mod25") && callList.IndexOf("mod2.x.y") < callList.IndexOf("mod25"); }