Exemple #1
0
        public void TestCollections1()
        {
            //
            // => Initialize
            //
            // ---------------                ---------------
            // |  P = 1,1,1  | (Root1)        |  P = 3,3,3  | (Root2)
            // |  V = 2,2,2  |                |             |
            // ---------------                ---------------
            //        
            // ---------------
            // |             | (Child)    
            // |             |
            // ---------------
            var root1Collection = new ParameterCollection("Root1");
            var root2Collection = new ParameterCollection("Root2");
            var childCollection = new ParameterCollection("Child");

            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            root1Collection.Set(paramP, new Vector3(1, 1, 1));
            root1Collection.Set(paramV, new Vector3(2, 2, 2));
            root2Collection.Set(paramP, new Vector3(3, 3, 3));

            //
            // => Add source Roo1 and Root2 to Child
            //
            // ---------------                ---------------
            // |  P = 1,1,1  | (Root1)        |  P = 3,3,3  | (Root2)
            // |  V = 2,2,2  |                |             |
            // ---------------                ---------------
            //        |                    / 
            // ---------------           /
            // |  P = ^,^,^  | (Child) / 
            // |  V = ^,^,^  |
            // ---------------
            // P = 3,3,3
            // V = 2,2,2
            childCollection.AddSources(root1Collection, root2Collection);

            Assert.AreEqual(childCollection.Count, 2);
            Assert.AreEqual(childCollection.Get(paramP), new Vector3(3, 3, 3));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));

            //
            // => Add source Roo1 and Root2 to Child
            //
            // ---------------                ---------------
            // |  P = 1,1,1  | (Root1)        |             | (Root2)
            // |  V = 2,2,2  |                |  V = 3,3,3  |
            // ---------------                ---------------
            //        |                    / 
            // ---------------           /
            // |  P = ^,^,^  | (Child) / 
            // |  V = ^,^,^  |
            // ---------------
            // P = 1,1,1
            // V = 3,3,3
            root2Collection.Remove(paramP);
            root2Collection.Set(paramV, new Vector3(3,3,3));
            Assert.AreEqual(childCollection.Count, 2);
            Assert.AreEqual(childCollection.Get(paramP), new Vector3(1, 1, 1));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));

            //
            // => Remove source Root1 for Child
            //
            // ---------------                ---------------
            // |  P = 1,1,1  | (Root1)        |             | (Root2)
            // |  V = 2,2,2  |                |  V = 3,3,3  |
            // ---------------                ---------------
            //                            / 
            // ---------------           /
            // |             | (Child) / 
            // |  V = ^,^,^  |
            // ---------------
            // V = 3,3,3
            childCollection.RemoveSource(root1Collection);
            Assert.AreEqual(childCollection.Count, 1);
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));

            //
            // => Inherit Root1 from Child
            //
            // ---------------               ---------------
            // |             | (Child) ------|             | (Root2)
            // |  V = ^,^,^  |               |  V = 3,3,3  |
            // ---------------               ---------------
            //        |                     
            // ---------------           
            // |  P = 1,1,1  | (Root1) 
            // |  V = 2,2,2  |         
            // ---------------         
            root1Collection.AddSources(childCollection);
            Assert.AreEqual(root1Collection.Count, 2);
            Assert.AreEqual(root1Collection.Get(paramP), new Vector3(1, 1, 1));
            Assert.AreEqual(root1Collection.Get(paramV), new Vector3(2, 2, 2));
        }
Exemple #2
0
        public void TestCollectionsBasicValues()
        {
            //
            // => Initialize
            //
            // ---------------
            // |             | (Root)
            // |             |
            // ---------------
            //        |
            // ---------------
            // |             | (Child)    
            // |             |
            // ---------------
            var rootCollection = new ParameterCollection("Root");
            var childCollection = new ParameterCollection("Child");
            childCollection.AddSources(rootCollection);

            //
            // => Set P and V on Root (1,1,1)
            //
            // ---------------
            // |   V = 1,1,1 | (Root)
            // |   P = 1,1,1 |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child)    
            // |   P = ^,^,^ |
            // ---------------
            var paramV = new ParameterKey<Vector3>("View");
            var paramP = new ParameterKey<Vector3>("Proj");
            rootCollection.Set(paramV, new Vector3(1, 1, 1));
            rootCollection.Set(paramP, new Vector3(1, 1, 1));

            // Verify collection.Count
            Assert.AreEqual(childCollection.Count, 2);

            // Verify collection.Contains
            Assert.AreEqual(childCollection.ContainsKey(paramV), true);
            Assert.AreEqual(childCollection.ContainsKey(paramP), true);

            //
            // => Set V in Root, Get from Child
            //
            // ---------------
            // |   V = 2,2,2 | (Root) 
            // |   P = 1,1,1 |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child)   
            // |   P = ^,^,^ |
            // ---------------
            // Verify the Get and returned value
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(1, 1, 1));
            rootCollection.Set(paramV, new Vector3(2,2,2));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));

            //
            // => Remove P from Root
            //
            // ---------------
            // |   V = 2,2,2 | (Root)  
            // |             |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child)    
            // ---------------
            rootCollection.Remove(paramP);
            Assert.AreEqual(childCollection.Count, 1);

            //
            // => Overrides V in Child (3,3,3)
            //
            // ---------------
            // |   V = 2,2,2 | (Root)  
            // |             |
            // ---------------
            //        |
            // ---------------
            // |   V = 3,3,3 | (Child)    
            // ---------------            
            childCollection.Set(paramV, new Vector3(3, 3, 3));
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(3, 3, 3));
            Assert.AreEqual(rootCollection.Get(paramV), new Vector3(2, 2, 2));

            //
            // => Reset Key V on Child
            //
            // ---------------
            // |   V = 2,2,2 | (Root)  
            // |             |
            // ---------------
            //        |
            // ---------------
            // |   V = ^,^,^ | (Child)    
            // ---------------            
            childCollection.Reset(paramV);
            Assert.AreEqual(childCollection.Get(paramV), new Vector3(2, 2, 2));
            Assert.AreEqual(rootCollection.Get(paramV), new Vector3(2, 2, 2));

            // Check that we cannot dipose a collction used as a source
            //Assert.Throws(typeof (InvalidOperationException), () => rootCollection.Release() );
            
            //
            // => Remove Root source from Child
            //
            // ---------------
            // |   V = 2,2,2 | (Root)  
            // |             |
            // ---------------
            //
            // ---------------
            // |             | (Child)    
            // ---------------            
            // Remove child using root and verify collection.Count
            childCollection.RemoveSource(rootCollection);
            Assert.AreEqual(childCollection.Count, 0);
        }