Exemplo n.º 1
0
        public void TestDictify()
        {
            using (var vw = new VowpalWabbit(new VowpalWabbitSettings(enableStringExampleGeneration: true, enableStringFloatCompact: true)))
                using (var serializer = VowpalWabbitSerializerFactory.CreateSerializer <MyDictifyContext>(vw.Settings).Create(vw))
                {
                    var dictionary = new Dictionary <string, string>();
                    var ctx        = new MyDictifyContext
                    {
                        A = 5,
                        B = new[] { 1f, 2f, 3f }
                    };

                    var str = serializer.SerializeToString(ctx, dictionary: dictionary);

                    Assert.AreEqual(" |  A:5 d0", str);

                    Assert.AreEqual(1, dictionary.Count);
                    Assert.IsTrue(dictionary.ContainsKey(" 0:1 1:2 2:3"));
                    Assert.AreEqual("d0", dictionary[" 0:1 1:2 2:3"]);
                }
        }
        public void TestDictify()
        {
            using (var vw = new VowpalWabbit(new VowpalWabbitSettings(enableStringExampleGeneration: true, enableStringFloatCompact: true)))
            using (var serializer = VowpalWabbitSerializerFactory.CreateSerializer<MyDictifyContext>(vw.Settings).Create(vw))
            {
                var dictionary = new Dictionary<string, string>();
                var ctx = new MyDictifyContext
                {
                    A = 5,
                    B = new[] { 1f, 2f, 3f }
                };

                var str = serializer.SerializeToString(ctx, dictionary: dictionary);

                Assert.AreEqual(" |  A:5 d0", str);

                Assert.AreEqual(1, dictionary.Count);
                Assert.IsTrue(dictionary.ContainsKey(" 0:1 1:2 2:3"));
                Assert.AreEqual("d0", dictionary[" 0:1 1:2 2:3"]);
            }
        }