ToDictionary() public method

public ToDictionary ( ) : IDictionary
return IDictionary
Example #1
0
        public void Test()
        {
            string s = "";

            for (int i = 0; i < Point.DIMENSIONS; i++)
            {
                s += (i + " ");
            }
            s += 10;
            Point p1 = new Point(s);

            Assert.AreEqual(p1.ToString(), s, "Testing toString");
            IDictionary ht1 = new ListDictionary();

            double [] side = new double[Point.DIMENSIONS];
            for (int i = 0; i < side.Length; i++)
            {
                side[i] = 1.0 * i;
            }
            ht1["side"]   = new ArrayList(side);
            ht1["height"] = 10.0;
            Point p2 = new Point(ht1);

            IDictionary ht2 = p2.ToDictionary();

            Assert.AreEqual(ht1["height"], ht2["height"], "Testing equality of heights");
            double [] side1 = (double[])((ArrayList)ht1["side"]).ToArray(typeof(double));
            double [] side2 = (double[])((ArrayList)ht2["side"]).ToArray(typeof(double));
            Assert.AreEqual(side1.Length, side2.Length, "Testing equality of dimensionality");
            for (int i = 0; i < side1.Length; i++)
            {
                Assert.AreEqual(side1[i], side2[i], String.Format("Testing equality of side: {0}", i));
            }
        }
Example #2
0
 public void Test() {
   string s = "";
   for (int i = 0; i < Point.DIMENSIONS; i++) {
     s += (i + " ");
   }
   s += 10;
   Point p1 = new Point(s);
   Assert.AreEqual(p1.ToString(), s, "Testing toString");
   IDictionary ht1 = new ListDictionary();
   double []side = new double[Point.DIMENSIONS];
   for (int i = 0; i < side.Length; i++) {
     side[i] = 1.0*i;
   }
   ht1["side"] = new ArrayList(side);
   ht1["height"] = 10.0;
   Point p2 = new Point(ht1);
   
   IDictionary ht2 = p2.ToDictionary();
   Assert.AreEqual(ht1["height"], ht2["height"], "Testing equality of heights");
   double []side1 = (double[]) ((ArrayList) ht1["side"]).ToArray(typeof(double));
   double []side2 = (double[]) ((ArrayList) ht2["side"]).ToArray(typeof(double));
   Assert.AreEqual(side1.Length, side2.Length, "Testing equality of dimensionality");      
   for (int i= 0; i < side1.Length; i++) {
     Assert.AreEqual(side1[i], side2[i], String.Format("Testing equality of side: {0}", i));
   }
 }