Beispiel #1
0
        public void CheckContains()
        {
            var a = SmallSet <string> .Create("A");

            Assert.True(a.Contains("A"));
            Assert.False(a.Contains("B"));
        }
Beispiel #2
0
 public override ValueProperties With(string propertyName, string propertyValue)
 {
     return(new FiniteValueProperties(new Dictionary <string, ISet <string> >(PropertyValues)
     {
         { propertyName, SmallSet <string> .Create(propertyValue) }
     }, _optional));
 }
Beispiel #3
0
        public void SingletonReadonly()
        {
            var set = SmallSet <string> .Create("A");

            Assert.True(set.IsReadOnly);
            Assert.Throws <InvalidOperationException>(() => set.Remove("A"));
            Assert.Throws <InvalidOperationException>(() => set.Clear());
        }
Beispiel #4
0
        public void BigSetSane()
        {
            var values = new[] { "A", "B" };
            var a      = SmallSet <string> .Create(values);

            var b = new HashSet <string>(values);
            var c = SmallSet <string> .Create(b);

            Assert.IsNotType(typeof(SmallSet <string>), a);
            Assert.IsNotType(typeof(SmallSet <string>), c);
            Assert.True(a.SetEquals(b));
            Assert.True(b.SetEquals(a));
            Assert.True(b.SetEquals(c));
        }
Beispiel #5
0
 public string InsertSmallSet(string name, int num, string color)
 {
     using (LuckyDrawEntities entitys = new LuckyDrawEntities())
     {
         try
         {
             SmallSet ss = new SmallSet();
             ss.name  = name;
             ss.num   = num;
             ss.color = color;
             entitys.SmallSets.Add(ss);
             entitys.SaveChanges();
         }
         catch (Exception)
         {
             return(JsonHelper.GetJson("false"));
         }
         return(JsonHelper.GetJson("true"));
     }
 }
Beispiel #6
0
 public string SubtractSmall(int id)
 {
     using (LuckyDrawEntities entitys = new LuckyDrawEntities())
     {
         try
         {
             List <Models.SmallSet> list = entitys.SmallSets.Where(a => a.id == id).ToList();
             if (list.Count > 0)
             {
                 SmallSet ss = list[0];
                 ss.num = ss.num - 1;
                 entitys.SaveChanges();
             }
         }
         catch (Exception)
         {
             return(JsonHelper.GetJson("false"));
         }
         return(JsonHelper.GetJson("true"));
     }
 }
Beispiel #7
0
        public void SingletonEqualitySane()
        {
            var a = SmallSet <string> .Create("A");

            var b = SmallSet <string> .Create(new HashSet <string> {
                "A"
            });

            var c = SmallSet <string> .Create(new[] { "A" });

            var d = new HashSet <string> {
                "A"
            };

            Assert.IsType(typeof(SmallSet <string>), a);
            Assert.IsType(typeof(SmallSet <string>), b);
            Assert.IsType(typeof(SmallSet <string>), c);
            Assert.IsNotType(typeof(SmallSet <string>), d);

            var diff = SmallSet <string> .Create("B");

            Assert.Equal(a, b);
            Assert.True(a.SetEquals(b));
            Assert.Equal(a, c);
            Assert.Equal(b, c);
            Assert.True(a.SetEquals(d));
            Assert.True(d.SetEquals(a));
            Assert.True(d.SetEquals(b));
            Assert.True(d.SetEquals(c));

            Assert.NotEqual(a, diff);
            Assert.NotEqual(b, diff);
            Assert.NotEqual(c, diff);

            Assert.False(diff.SetEquals(a));
            Assert.False(a.SetEquals(diff));
            Assert.False(diff.SetEquals(b));
            Assert.False(diff.SetEquals(c));
            Assert.False(diff.SetEquals(d));
        }
Beispiel #8
0
            public override ValueProperties WithoutAny(string propertyName)
            {
                ISet <string> optional = _optional;
                Dictionary <string, ISet <string> > propertyValues = PropertyValues;

                if (optional != null && optional.Contains(propertyName))
                {
                    if (optional.Count == 1)
                    {
                        optional = null;
                    }
                    else
                    {
                        optional = SmallSet <string> .Create(optional.Where(v => v != propertyName));
                    }
                }
                if (propertyValues.ContainsKey(propertyName))
                {
                    propertyValues = propertyValues.Where(k => k.Key != propertyName).ToDictionary(k => k.Key, k => k.Value);
                }
                return(new FiniteValueProperties(propertyValues, optional));
            }
Beispiel #9
0
 public override ValueProperties WithoutAny(string propertyName)
 {
     return(new NearlyInfiniteValueProperties(SmallSet <string> .Create(propertyName)));
 }
        public override ValueProperties DeserializeImpl(IFudgeFieldContainer ffc, IFudgeDeserializer deserializer)
        {
            var withoutMessage = ffc.GetMessage("without");

            if (withoutMessage != null)
            {
                if (withoutMessage.Any())
                {
                    var without    = withoutMessage.Select(f => f.Value).Cast <string>();
                    var withoutSet = SmallSet <string> .Create(without);

                    return(new NearlyInfiniteValueProperties(withoutSet));
                }
                else
                {
                    return(InfiniteValueProperties.Instance);
                }
            }

            var withMessage = ffc.GetMessage("with");

            if (withMessage == null)
            {
                return(EmptyValueProperties.Instance);
            }

            var properties            = new Dictionary <string, ISet <string> >(withMessage.GetNumFields());
            HashSet <string> optional = null;

            foreach (var field in withMessage)
            {
                var name = string.Intern(field.Name); // Should be a small static set

                var fieldType = field.Type;
                if (Equals(fieldType, StringFieldType.Instance))
                {
                    var value = (string)field.Value;
                    properties.Add(name, SmallSet <string> .Create(value));
                }
                else if (Equals(fieldType, IndicatorFieldType.Instance))
                {
                    //withAny
                    properties.Add(name, new HashSet <string>());
                }
                else if (Equals(fieldType, FudgeMsgFieldType.Instance))
                {
                    var propMessage = (IFudgeFieldContainer)field.Value;
                    var hashSet     = new HashSet <string>();
                    foreach (var fudgeField in propMessage)
                    {
                        if (fudgeField.Value == IndicatorType.Instance)
                        {
                            if (fudgeField.Name != "optional")
                            {
                                throw new ArgumentException();
                            }
                            optional = optional ?? new HashSet <string>();
                            optional.Add(name);
                        }
                        else
                        {
                            string value = (string)fudgeField.Value;
                            hashSet.Add(value);
                        }
                    }
                    if (hashSet.Any())
                    {
                        properties.Add(name, hashSet);
                    }
                }
            }

            return(new FiniteValueProperties(properties, optional == null ? null : SmallSet <string> .Create(optional)));
        }