コード例 #1
0
        public void DefaultCollectionValue_Get_OnNonMapItemNotExistsNoCreate()
        {
            DefaultLongValue <G>     key           = new DefaultLongValue <G>(20);
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(4), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            EntryValuePointer <G>    result = sut.Get(key, false, valueProvider) as EntryValuePointer <G>;

            Assert.False(sut.IsMap);
            Assert.Null(result);
        }
コード例 #2
0
        public void DefaultCollectionValue_Get_OnMapItemExists(bool create)
        {
            DefaultLongValue <G>     key           = new DefaultLongValue <G>(4);
            IValuable <G>            value         = Mock.Of <IValuable <G> >();
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultDoubleValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultDoubleValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { key, new ValuePointer <G> {
                      Value = value
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultLongValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            EntryValuePointer <G>    result = sut.Get(key, create, valueProvider) as EntryValuePointer <G>;

            Assert.Equal(key, result.Key);
            Assert.Equal(value, result.Value);
            Assert.Equal(3, result.Index);
            Assert.True(result.IsSet);
        }
コード例 #3
0
        public void DefaultCollectionValue_Get_OnMapItemNotExistsCreateEntry()
        {
            DefaultLongValue <G>     key           = new DefaultLongValue <G>(20);
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultDoubleValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultDoubleValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultLongValue <G>(4), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultLongValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            EntryValuePointer <G>    result = sut.Get(key, true, valueProvider) as EntryValuePointer <G>;

            Assert.True(sut.IsMap);
            Assert.Equal(key, result.Key);
            Assert.Null(result.Value);
            Assert.Equal(6, result.Index);
            Assert.False(result.IsSet);
        }
コード例 #4
0
        public void DefaultCollectionValue_KeyOf_Present()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            DefaultLongValue <G>     key           = new DefaultLongValue <G>(4);
            IValuable <G>            value         = Mock.Of <IValuable <G> >();
            Dictionary <IValuable <G>, ValuePointer <G> > values = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultDoubleValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultDoubleValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { key, new ValuePointer <G> {
                      Value = value
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultLongValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };

            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            IValuable <G>            result = sut.KeyOf(value, valueProvider);

            Assert.Equal(key, result);
        }
コード例 #5
0
        public void DefaultLongValue_Add_NonMapCollection(long value)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > collectionValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(0), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(1), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(2), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } }
            };
            DefaultArrayMapValue <G> collectionValue = new DefaultArrayMapValue <G>(collectionValues, valueProvider);

            DefaultLongValue <G>       sut    = new DefaultLongValue <G>(value);
            DefaultCollectionValue <G> result = (DefaultCollectionValue <G>)sut.Add(collectionValue, valueProvider);

            List <KeyValuePair <IValuable <G>, ValuePointer <G> > > entries = result.GetEntries();

            Assert.Equal(Enumerable.Range(0, 4), entries.Select(kv => kv.Key).Cast <IValue>().Select(v => Convert.ToInt32(v.GetData())));
            Assert.Equal(new IValuable <G>[] { sut }.Concat(collectionValues.Values.Select(v => v.Value)), entries.Select(kv => kv.Value).Select(vp => vp.Value));
            Assert.False(result.IsMap);
            Assert.Equal(Enumerable.Range(0, 4), entries.Select(e => e.Value).Cast <EntryValuePointer <G> >().Select(v => v.Index));
        }
コード例 #6
0
        public void DefaultLongValue_Add(long value, object otherVal, Type resultType, bool throwsException)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultLongValue <G> sut      = new DefaultLongValue <G>(value);
            IValue <G>           newValue = null;
            Action action = () =>
            {
                newValue = (IValue <G>)sut.Add(otherVal.GetAsValue(), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }

            if (!throwsException)
            {
                switch (otherVal)
                {
                case double doubleVal:
                    Assert.Equal(Convert.ChangeType(value + doubleVal, resultType), newValue.GetData());
                    break;

                case int intVal:
                    Assert.Equal(Convert.ChangeType(value + intVal, resultType), newValue.GetData());
                    break;

                case long longVal:
                    Assert.Equal(Convert.ChangeType(value + longVal, resultType), newValue.GetData());
                    break;

                case string strVal:
                    Assert.Equal(Convert.ChangeType(value + strVal, resultType), newValue.GetData());
                    break;

                case null:
                    Assert.Equal(sut, newValue);
                    break;
                }
            }
        }
コード例 #7
0
        public void DefaultLongValue_IsNotEqualTo(long value, object otherVal, bool throwsException)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultLongValue <G> sut      = new DefaultLongValue <G>(value);
            IValue <G>           newValue = null;
            Action action = () =>
            {
                newValue = (IValue <G>)sut.IsNotEqualTo(otherVal.GetAsValue(), valueProvider);
            };

            if (throwsException)
            {
                Assert.Throws <EngineRuntimeException>(action);
            }
            else
            {
                action();
            }


            if (!throwsException)
            {
                switch (otherVal)
                {
                case double doubleVal:
                    Assert.Equal(value != doubleVal, newValue.GetData());
                    break;

                case int intVal:
                    Assert.Equal(value != intVal, newValue.GetData());
                    break;

                case long longVal:
                    Assert.Equal(value != longVal, newValue.GetData());
                    break;

                default:
                    Assert.True((bool)newValue.GetData());
                    break;
                }
            }
        }
コード例 #8
0
        public void DefaultLongValue_Add_MapCollection(long value)
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            Dictionary <IValuable <G>, ValuePointer <G> > collectionValues = new Dictionary <IValuable <G>, ValuePointer <G> >()
            {
                { new DefaultIntValue <G>(3), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(4), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
                { new DefaultIntValue <G>(5), new ValuePointer <G> {
                      Value = Mock.Of <IValuable <G> >()
                  } },
            };
            DefaultArrayMapValue <G> collectionValue = new DefaultArrayMapValue <G>(collectionValues, valueProvider);

            DefaultLongValue <G> sut = new DefaultLongValue <G>(value);

            Assert.Throws <EngineRuntimeException>(() =>
            {
                sut.Add(collectionValue, valueProvider);
            });
        }