示例#1
0
        public void Count_TwoItemsAdded_ReturnsTwo()
        {
            // arrange
            string f1 = "F1";
            string f2 = "F2";
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical("F1"));
            featureManager.Add(new FeatureNumerical("F2"));
            ItemNumericalSet set = new ItemNumericalSet(featureManager);

            ItemNumerical i1 = set.CreateItem();

            i1.SetValue(f1, 3);
            i1.SetValue(f2, 4.7f);
            set.AddItem(i1);

            ItemNumerical i2 = set.CreateItem();

            i2.SetValue(f1, 1);
            i2.SetValue(f2, 2.1f);
            set.AddItem(i2);

            // act
            int qty = set.Count();

            // assert
            Assert.AreEqual(2, qty);
        }
示例#2
0
        private void FillItemSet_Features4_Items15()
        {
            string f1 = "F1";
            string f2 = "F2";
            string f3 = "F3";
            string f4 = "F4";

            _set = new ItemNumericalSet(new List <string> {
                f1, f2, f3, f4
            });

            const int qty = 15;

            int[] a1 = new int[qty] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12, 13, 14, 15
            };
            float[] a2 = new float[qty] {
                1f, 0.2f, 2.3f, 4.1f, 4f, 2.76f, 1.2f, 3f, 3.14f, 0f, 2.2f, 1.4f, 1.01f, 0.3f, 0.23f
            };
            float[] a3 = new float[qty] {
                5f, 1.2f, 6.1f, 2.2f, 1f, 2.6f, 8.2f, 2f, 4.1f, 1.4f, 0.2f, 2.4f, 1.1f, 4.3f, 1.3f
            };
            int[] a4 = new int[qty] {
                1, 2, 6, 3, 1, 0, 4, 4, 2, 5, 0, 3, 3, 1, 2
            };
            for (int i = 0; i < qty; i++)
            {
                ItemNumerical item = _set.CreateItem();
                item.SetValue(f1, a1[i]);
                item.SetValue(f2, a2[i]);
                item.SetValue(f3, a3[i]);
                item.SetValue(f4, a4[i]);
                _set.AddItem(item);
            }
        }
示例#3
0
        private void FillItemSet_Features2_Items15()
        {
            string f1 = "F1";
            string f2 = "F2";

            _set = new ItemNumericalSet(new List <string> {
                f1, f2
            });

            const int qty = 15;

            //int[] a1 = new int[qty] { -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7 };
            //int[] a1 = new int[qty] { 0, 0, 0, 0, 0, 0, 0, 7, 8, 9, 10, 11, 12, 13, 14 };
            int[] a1 = new int[qty] {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };
            //int[] a1 = new int[qty] { -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
            //int[] a1 = new int[qty] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
            //int[] a1 = new int[qty] { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0 };
            //int[] a1 = new int[qty] { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
            float[] a2 = new float[qty] {
                1f, 0.2f, 2.3f, 4.1f, 4f, 2.76f, 1.2f, 3f, 3.14f, 0f, 2.1f, 3.5f, 1.4f, 2.9f, 0.4f
            };
            for (int i = 0; i < qty; i++)
            {
                ItemNumerical item = _set.CreateItem();
                item.SetValue(f1, a1[i]);
                item.SetValue(f2, a2[i]);
                _set.AddItem(item);
            }
        }
示例#4
0
        private void FillItemSet_Features2_Items10()
        {
            string f1 = "F1";
            string f2 = "F2";

            _set = new ItemNumericalSet(new List <string> {
                f1, f2
            });

            const int qty = 10;

            int[] a1 = new int[qty] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            };
            float[] a2 = new float[qty] {
                1f, 0.2f, 2.3f, 4.1f, 4f, 2.76f, 1.2f, 3f, 3.14f, 0f
            };
            for (int i = 0; i < qty; i++)
            {
                ItemNumerical item = _set.CreateItem();
                item.SetValue(f1, a1[i]);
                item.SetValue(f2, a2[i]);
                _set.AddItem(item);
            }
        }
示例#5
0
        public void CreateItem_ReturnsItem()
        {
            // arrange
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical("F1"));
            featureManager.Add(new FeatureNumerical("F2"));
            ItemNumericalSet set = new ItemNumericalSet(featureManager);

            // act
            ItemNumerical item = set.CreateItem();

            // assert
            Assert.IsNotNull(item);
            Assert.AreEqual(true, item.HasValue("F1") & item.HasValue("F2"));
        }
示例#6
0
        public void GetFeatureNames_Item_ReturnsListOfNames()
        {
            // arrange
            List <string> featureNames = new List <string> {
                "F1", "F2"
            };
            ItemNumericalSet set = new ItemNumericalSet(featureNames);
            ItemNumerical    i   = set.CreateItem();

            set.AddItem(i);

            // act
            List <string> names = i.GetFeatureNames();

            // assert
            CollectionAssert.AreEqual(featureNames, names);
        }
示例#7
0
        public void AddFeature_ItemSetFeatures1Items1_ReturnsItemHasFeature()
        {
            // arrange
            List <string> featureNames = new List <string> {
                "F1"
            };
            ItemNumericalSet set = new ItemNumericalSet(featureNames);
            ItemNumerical    i   = set.CreateItem();

            i.SetValue("F1", 3.2);
            set.AddItem(i);

            // act
            bool r = set.AddFeature("F2");

            // assert
            Assert.AreEqual(true, r & i.HasValue("F2"));
        }
示例#8
0
        public void GetSeparateValue_ItemSetFeatures1Items1_ReturnsSeparateValue()
        {
            // arrange
            ISplitter        splitter = new SplitterRss();
            ItemNumericalSet set      = new ItemNumericalSet(new List <string>()
            {
                "F1"
            });
            ItemNumerical item = set.CreateItem();

            item.SetValue("F1", 1);
            set.AddItem(item);

            // act
            var sv = splitter.Split(set, "F1");

            // assert
            Assert.IsNull(sv);
        }
示例#9
0
        public void GetSeparateValue_ItemSetFeatures2Items5_ReturnsSeparateValue()
        {
            // arrange
            string f1 = "F1";
            string f2 = "F2";
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical(f1));
            featureManager.Add(new FeatureNumerical(f2));
            _set = new ItemNumericalSet(featureManager);

            int[] a1 = new int[5] {
                1, 2, 3, 4, 5
            };
            float[] a2 = new float[5] {
                1f, 0.2f, 2.3f, 4.1f, 4f
            };
            for (int i = 0; i < 5; i++)
            {
                ItemNumerical item = _set.CreateItem();
                item.SetValue(f1, a1[i]);
                item.SetValue(f2, a2[i]);
                _set.AddItem(item);
            }

            ISplitter splitter = new SplitterRss();

            // act
            FeatureNumericalValue sv = splitter.Split(_set, "F1");
            double fv = Math.Round(sv.FeatureValue, 2);

            // assert
            Assert.IsNotNull(sv);
            //Assert.AreEqual(3.15, fv);
            Assert.AreEqual(1.65, fv);
        }
示例#10
0
        public void Clone_Item_ReturnsClone()
        {
            // arrange
            string f1 = "F1";
            string f2 = "F2";
            FeatureNumericalManager featureManager = new FeatureNumericalManager();

            featureManager.Add(new FeatureNumerical(f1));
            featureManager.Add(new FeatureNumerical(f2));
            ItemNumericalSet set  = new ItemNumericalSet(featureManager);
            ItemNumerical    item = set.CreateItem();

            item.SetValue(f1, 5);
            item.SetValue(f2, 3.8f);

            // act
            ItemNumerical clone = item.Clone();

            item.SetValue(f1, 10);

            // assert
            Assert.AreEqual(5, clone.GetValue(f1));
            Assert.AreEqual(3.8f, clone.GetValue(f2));
        }
示例#11
0
 public IItemNumerical CreateItem()
 {
     return(_set.CreateItem());
 }