Пример #1
0
        public void TestConstructors()
        {
            NamedMultiset            testConstructor1 = new NamedMultiset();
            Dictionary <string, int> data1            = testConstructor1.ToDictionary();

            Assert.AreEqual(0, data1.Count);

            Dictionary <string, int> testDictionary = new Dictionary <string, int> {
                { "key", 2 }
            };
            NamedMultiset            testConstructor2 = new NamedMultiset(testDictionary);
            Dictionary <string, int> data2            = testConstructor2.ToDictionary();

            Assert.AreEqual(1, data2.Count);
            Assert.IsTrue(data2.ContainsKey("key"));
            Assert.AreEqual(2, data2["key"]);

            List <ISimulationObject> testList = new List <ISimulationObject> {
                new Protein("testName")
            };
            NamedMultiset            testConstructor3 = new NamedMultiset(testList);
            Dictionary <string, int> data3            = testConstructor3.ToDictionary();

            Assert.AreEqual(1, data3.Count);
            Assert.IsTrue(data3.ContainsKey("testName"));
            Assert.AreEqual(1, data3["testName"]);
        }
Пример #2
0
        public void TestRemove()
        {
            NamedMultiset set = new NamedMultiset {
                "item1", "item1", "item2"
            };

            Dictionary <string, int> data = set.ToDictionary();

            Assert.AreEqual(2, data.Count);
            Assert.AreEqual(2, data["item1"]);
            Assert.AreEqual(1, data["item2"]);

            Assert.IsTrue(set.Remove("item1"));

            data = set.ToDictionary();
            Assert.AreEqual(2, data.Count);
            Assert.AreEqual(1, data["item1"]);
            Assert.AreEqual(1, data["item2"]);

            Assert.IsTrue(set.Remove("item1"));

            data = set.ToDictionary();
            Assert.AreEqual(1, data.Count);
            Assert.AreEqual(1, data["item2"]);

            Assert.IsFalse(set.Remove("item3"));
            Assert.IsFalse(set.Remove("item1"));
        }
Пример #3
0
        public void TestToString()
        {
            NamedMultiset set = new NamedMultiset {
                "item1", "item1", "item2"
            };

            Assert.AreEqual("[item1, 2]\n[item2, 1]", set.ToString());
        }
Пример #4
0
        public void TestIsSubsetOf()
        {
            NamedMultiset set1 = new NamedMultiset {
                "item1", "item2"
            };
            NamedMultiset set2 = new NamedMultiset {
                "item1"
            };

            Assert.IsTrue(set2.IsSubsetOf(set1));
            Assert.IsFalse(set1.IsSubsetOf(set2));

            set1.Add("item1");
            Assert.IsTrue(set2.IsSubsetOf(set1));
        }
Пример #5
0
        public void TestClear()
        {
            NamedMultiset            set  = new NamedMultiset();
            Dictionary <string, int> data = set.ToDictionary();

            Assert.AreEqual(0, data.Count);

            set.Add("item1");
            set.Add("item2");

            data = set.ToDictionary();
            Assert.AreEqual(2, data.Count);

            set.Clear();
            data = set.ToDictionary();
            Assert.AreEqual(0, data.Count);
        }
Пример #6
0
        public void TestEquals()
        {
            NamedMultiset set1 = new NamedMultiset {
                "item1"
            };
            NamedMultiset set2 = new NamedMultiset {
                "item1"
            };

            Assert.IsTrue(set1.Equals(set2));

            NamedMultiset set3 = new NamedMultiset();

            Assert.IsFalse(set1.Equals(set3));

            set1.Add("item1");
            Assert.IsFalse(set1.Equals(set2));
        }
Пример #7
0
        public void GetObjectsNearConnectorTest2()
        {
            var testTile = _testTilesWorld.First();
            // Construct a lower part of a dodecahedron (1+5 tiles)

            TileInSpace newlyCreatedTile;

            Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], testTile.Connectors[0], out newlyCreatedTile));
            Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], testTile.Connectors[1], out newlyCreatedTile));
            Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], testTile.Connectors[2], out newlyCreatedTile));
            Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], testTile.Connectors[3], out newlyCreatedTile));
            Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], testTile.Connectors[4], out newlyCreatedTile));
            //Assert.IsTrue(_testTilesWorld.Add(_testMSystem.Tiles["q1"], _testTilesWorld.ToArray()[1].Connectors[3]));

            var aBox = new Box3D(new Point3D(-5.87, -8.09, 0.01), new Point3D(-5.37, -7.59, 0.5));
            var aSet = new NamedMultiset(new[] { _testMSystem.FloatingObjects["a"] });

            for (int i = 0; i < 100; i++)
            {
                _testFltObjectsWorld.AddAt(aSet, aBox.RandomPoint());
            }

            var cBox = new Box3D(new Point3D(-5.87, -8.09, -0.5), new Point3D(-5.37, -7.59, -0.01));
            var cSet = new NamedMultiset(new[] { _testMSystem.FloatingObjects["c"] });

            for (int i = 0; i < 100; i++)
            {
                _testFltObjectsWorld.AddAt(cSet, cBox.RandomPoint());
            }

            _testFltObjectsWorld.FinalizeStep(true);

            for (int i = 2; i < 4; i++)
            {
                var result = _testFltObjectsWorld.GetNearObjects(testTile.Connectors[i], v_InfiniteMultiset);
                Assert.AreEqual(100, result.Count(obj => obj.Name == "a"));
                Assert.AreEqual(102, result.Count(obj => obj.Name == "c"));
                // TODO low priority t2 extra objects were created during ADD of tiles but generally they need not be there
                // add different floating objects to the test xml file and use them instead of "a","c"
            }
        }
Пример #8
0
 /// <summary>
 /// Deserialize given XML list of signal objects.
 /// </summary>
 /// <param name="glueTuples">XML element list of glue tuples.</param>
 /// <exception cref="MissingXmlAttribute">If some attribute of floating object is missing.</exception>
 /// <exception cref="MissingXmlElement">If some element of floating object is missing.</exception>
 private void DeserializeSignalObjects(List <XElement> glueTuples)
 {
     foreach (XElement glueTuple in glueTuples)
     {
         string        nameOfTheGlue1      = Xmlizer.GetAttributeValueWithException(glueTuple, "glueTuple", "glue1");
         string        nameOfTheGlue2      = Xmlizer.GetAttributeValueWithException(glueTuple, "glueTuple", "glue2");
         NamedMultiset signalObjects       = new NamedMultiset();
         XElement      objectElement       = glueTuple.Element("objects");
         List <string> floatingObjectNames = Xmlizer.GetAttributeValueWithException(objectElement, "objects", "value").Split(',').ToList();
         foreach (string floatingObjectName in floatingObjectNames)
         {
             if (!FloatingObjects.ContainsKey(floatingObjectName))
             {
                 throw new InvalidOperationException(string.Format("Floating object named '{0}' is not defined in input xml file.",
                                                                   floatingObjectName));
             }
             signalObjects.Add(floatingObjectName);
         }
         //TODO check if it find correct value
         GluePRelation[new Tuple <Glue, Glue>(Glues[nameOfTheGlue1], Glues[nameOfTheGlue2])] = signalObjects;
     }
 }