Exemplo n.º 1
0
 public override void FinalizeEntry(IValuable <G> key, EntryValuePointer <G> entryValuePointer)
 {
     lock (this)
     {
         _valuesDictionary[key] = entryValuePointer;
     }
 }
Exemplo n.º 2
0
        public IValuable GetValuable(string id)
        {
            IValuable foundValuable = null;

            foreach (IValuable valuable in valuables)
            {
                if (valuable is Merchandise)
                {
                    Merchandise merchandise = valuable as Merchandise;
                    if (merchandise.ItemId == id)
                    {
                        foundValuable = merchandise;
                    }
                }

                if (valuable is Course)
                {
                    Course course = valuable as Course;

                    if (course.Name == id)
                    {
                        foundValuable = course;
                    }
                }
            }

            return(foundValuable);
        }
Exemplo n.º 3
0
        public IValuable GetValuable(string id)
        {
            IValuable obj = valuables[0];

            valuables.ForEach(x =>
            {
                if (x is Book book)
                {
                    if (book.ItemId == id)
                    {
                        obj = book;
                    }
                }
                else if (x is Amulet amulet)
                {
                    if (amulet.ItemId == id)
                    {
                        obj = amulet;
                    }
                }
                else if (x is Course course)
                {
                    if (course.Name == id)
                    {
                        obj = course;
                    }
                }
            });
            return(obj);
        }
Exemplo n.º 4
0
        public void DefaultActionValue_Add(object otherVal, bool throwsException)
        {
            G groupState = Mock.Of <G>();
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            DefaultActionValue <G> sut      = new DefaultActionValue <G>(groupState, 10);
            IValuable <G>          newValue = null;
            Action action = () =>
            {
                newValue = sut.Add(valueProvider.GetAsValue(otherVal), valueProvider);
            };

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


            if (!throwsException)
            {
                switch (otherVal)
                {
                case null:
                    Assert.Equal(sut, newValue);
                    break;
                }
            }
        }
Exemplo n.º 5
0
        public void DefaultCollectionValue_GetAt()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            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> >()
                  } },
                { 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 = value
                  } }
            };

            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            ValuePointer <G>         result = sut.GetAt(new DefaultIntValue <G>(5), valueProvider);

            Assert.Equal(value, result.Value);
        }
Exemplo n.º 6
0
        public void DefaultCollectionValue_ContainsValue_Present()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            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> >()
                  } },
                { new DefaultLongValue <G>(4), 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);
            bool result = sut.ContainsValue(value, valueProvider);

            Assert.True(result);
        }
Exemplo n.º 7
0
        public IValuable <G> Minus(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case IValue <G, string> stringValue:
                return(Minus(stringValue.Data, valueProvider));

            case IValue <G, int> intValue:
                return(Minus(intValue.Data.ToString(), valueProvider));

            case IValue <G, double> doubleValue:
                return(Minus(doubleValue.Data.ToString(), valueProvider));

            case IValue <G, long> longValue:
                return(Minus(longValue.Data.ToString(), valueProvider));

            case IValue <G, bool> booleanValue:
                return(Minus(booleanValue.Data.ToString(), valueProvider));

            case INullValue <G> _:
                return(this);

            default:
                throw new EngineRuntimeException("Invalid values for subtraction");
            }
        }
Exemplo n.º 8
0
        public IValuable <G> Add(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case IValue <G, string> stringValue:
                return(Add(stringValue.Data, valueProvider));

            case IValue <G, int> intValue:
                return(Add(intValue.Data.ToString(), valueProvider));

            case IValue <G, double> doubleValue:
                return(Add(doubleValue.Data.ToString(), valueProvider));

            case IValue <G, long> longValue:
                return(Add(longValue.Data.ToString(), valueProvider));

            case IValue <G, bool> booleanValue:
                return(Add(booleanValue.Data.ToString().ToLower(), valueProvider));

            case ICollectionValue <G> collectionValue:
                return(Add(collectionValue, valueProvider));

            case INullValue <G> _:
                return(this);

            default:
                throw new EngineRuntimeException("Invalid values for addition");
            }
        }
Exemplo n.º 9
0
        private static string ToJsonString <G>(IValuable <G> input, int maxDepth = 30) where G : IGroupState <G>, new()
        {
            string jsonValue = null;

            if (input == null)
            {
                jsonValue = "null";
            }
            else if (input is ICollectionValue <G> collectionValue)
            {
                jsonValue = maxDepth <= 0
                                        ? "overflow"
                                        : collectionValue is DefaultCollectionValue <G> defaultCollectionValue && (defaultCollectionValue.IsMap || defaultCollectionValue == null)
                                                ? $"{{{string.Join(", ", collectionValue.GetEntries().Select(entry => $"{ToJsonString(entry.Key, 2)}: {ToJsonString(entry.Value.Value, maxDepth - 1)}"))}}}"
                                                : $"[{string.Join(", ", collectionValue.GetValues().Select(item => ToJsonString(item.Value, maxDepth - 1)))}]";
            }
            else if (input is IActionValue <G> )
            {
                jsonValue = "action pointer";
            }
            else if (input is IGroupValue <G> groupValue)
            {
                jsonValue = $"{groupValue.State.Group.GroupName} pointer";
            }
            else
            {
                IValue value = input as IValue;
                jsonValue = ToValueString(value?.GetData() ?? input?.ToString() ?? "undefined");
            }
            return(jsonValue);
        }
Exemplo n.º 10
0
 public override void Remove(IValuable <G> key, IValueProvider <G> valueProvider)
 {
     lock (this)
     {
         if (IsMap)
         {
             if (_valuesDictionary.TryGetValue(key, out EntryValuePointer <G> pointer))
             {
                 int index = pointer.Index;
                 _valuesDictionary.Remove(key);
                 _valuesList.RemoveAt(index);
                 for (int i = index; i < _valuesList.Count; i++)
                 {
                     _valuesList[i].Index = i;
                 }
             }
         }
         else
         {
             int index = AsArrayIndex(key).Value;
             if (index >= 0 && index < _valuesList.Count)
             {
                 _valuesList.RemoveAt(index);
                 for (int i = index; i < _valuesList.Count; i++)
                 {
                     _valuesList[i].Index = i;
                     _valuesList[i].Key   = valueProvider.GetInt(i);
                 }
             }
         }
     }
 }
Exemplo n.º 11
0
        public void DefaultCollectionValue_KeyOf_NotPresent()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();
            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> >()
                  } },
                { 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);
            IValuable <G>            result = sut.KeyOf(value, valueProvider);

            Assert.Null(result);
        }
Exemplo n.º 12
0
        public void DefaultCollectionValue_Get_OnNonMapItemExists(bool create)
        {
            DefaultIntValue <G>      key           = new DefaultIntValue <G>(3);
            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 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> >()
                  } },
                { key, new ValuePointer <G> {
                      Value = value
                  } },
                { 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, create, valueProvider) as EntryValuePointer <G>;

            Assert.False(sut.IsMap);
            Assert.Equal(key, result.Key);
            Assert.Equal(value, result.Value);
            Assert.Equal(3, result.Index);
            Assert.True(result.IsSet);
        }
Exemplo n.º 13
0
        public IValuable GetValuable(string id)
        {
            IValuable result = null;

            foreach (IValuable valueable in valueables)
            {
                if (valueable is Merchandise merchandise)
                {
                    if (merchandise.ItemId.Equals(id))
                    {
                        result = merchandise;
                    }
                    return(result);
                }
                else if (valueable is Course course)
                {
                    if (course.Name.Equals(id))
                    {
                        result = course;
                    }
                    return(result);
                }
            }
            return(result);
        }
Exemplo n.º 14
0
 public LSystemData(string axiom, IValuable angle, float depthFactor)
 {
     Rules       = new List <ARule>();
     Axiom       = axiom;
     Angle       = angle;
     DepthFactor = depthFactor;
 }
Exemplo n.º 15
0
 public EntryValuePointer(ICollectionValue <G> collection, IValuable <G> key, int index, IValueProvider <G> valueProvider, bool isSet = false)
 {
     Collection    = collection;
     Key           = key;
     IsSet         = isSet;
     Index         = index;
     ValueProvider = valueProvider;
 }
Exemplo n.º 16
0
        public ValuePointer <G> Get(IValuable <G> value, bool createNonExistent, IValueProvider <G> valueProvider)
        {
            IValue <G, int> index = (IValue <G, int>)value;

            return(new ValuePointer <G> {
                Value = valueProvider.GetString(Data[index.Data].ToString())
            });
        }
Exemplo n.º 17
0
        private Type GetOperandDeclareType(IValuable operand)
        {
            if (operand is LocalOperand) return ((LocalOperand)operand).Value.LocalType;
            if (operand is FieldOperand) return ((FieldOperand)operand).Value.FieldType;

            // TODO PropertyOperand 추가 해야함
            throw new NotSupportedException(operand.ToString());
        }
Exemplo n.º 18
0
        private static void ExecuteInstructionRPower(IInstructionExecutor <GroupState> executor, ExecutionState <GroupState> executionState, object[] payload, StackList <ValuePointer <GroupState> > stackRegister, StackList <StackValuePointer <GroupState> > stackPointers)
        {
            IValue <GroupState>    secondValue = (IValue <GroupState>)stackRegister.TakeLast().Value;
            IValue <GroupState>    firstValue  = (IValue <GroupState>)stackRegister.Last().Value;
            IValuable <GroupState> result      = executor.ValueProvider.GetReducedValue(Math.Pow(Convert.ToDouble(firstValue.GetData()), Convert.ToDouble(secondValue.GetData())));

            stackRegister.SetLast(new ValuePointer <GroupState> {
                Value = result
            });
        }
Exemplo n.º 19
0
 public override void Remove(IValuable <G> key, IValueProvider <G> valueProvider)
 {
     lock (this)
     {
         if (_valuesDictionary.TryGetValue(key, out EntryValuePointer <G> pointer))
         {
             _valuesDictionary.Remove(key);
         }
     }
 }
 public void Remove(IValuable valuable)
 {
     if (valuable is FacilityObject)
     {
         Remove((FacilityObject)valuable);
     }
     else
     {
         GetAll().OfType <ValuablesContainer>().ForEach(y => y.Remove(valuable));
     }
 }
Exemplo n.º 21
0
        public IValuable <G> RightShift(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case IValue <G, int> intValue:
                return(RightShift(intValue.Data, valueProvider));

            default:
                throw new EngineRuntimeException("Invalid values for right shift");
            }
        }
Exemplo n.º 22
0
        public IValuable <G> IsNotEqualTo(IValuable <G> valuable, IValueProvider <G> valueProvider)
        {
            switch (valuable)
            {
            case IValue <G, bool> booleanValue:
                return(IsNotEqualTo(booleanValue, valueProvider));

            default:
                return(valueProvider.True);
            }
        }
Exemplo n.º 23
0
        public IValuable <G> Or(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case IValue <G, bool> booleanValue:
                return(Or(booleanValue, valueProvider));

            default:
                throw new EngineRuntimeException("Invalid values for or");
            }
        }
Exemplo n.º 24
0
        public IValuable <G> IsNotEqualTo(IValuable <G> valuable, IValueProvider <G> valueProvider)
        {
            switch (valuable)
            {
            case IValue <G, string> stringValue:
                return(IsNotEqualTo(stringValue, valueProvider));

            default:
                return(valueProvider.True);
            }
        }
Exemplo n.º 25
0
        public override int CompareTo(IValuable other)
        {
            var asQuadruple = other as Quadruple;

            if (asQuadruple != null)
            {
                return(CompareTo(asQuadruple));
            }

            return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]);
        }
Exemplo n.º 26
0
        public void DefaultCollectionValue_GetValues()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            IValuable <G>[] values = new IValuable <G>[] { Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >() };

            DefaultArrayMapValue <G> sut    = new DefaultArrayMapValue <G>(values, valueProvider);
            List <ValuePointer <G> > result = sut.GetValues();

            Assert.Equal(values, result.Select(p => p.Value));
        }
Exemplo n.º 27
0
        public IValuable <G> Add(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case ICollectionValue <G> collectionValue:
                return(Add(collectionValue, valueProvider));

            default:
                throw new EngineRuntimeException("Invalid values for addition");
            }
        }
Exemplo n.º 28
0
        public IValuable <G> IsEqualTo(IValuable <G> value, IValueProvider <G> valueProvider)
        {
            switch (value)
            {
            case INullValue <G> _:
                return(valueProvider.True);

            default:
                return(valueProvider.False);
            }
        }
Exemplo n.º 29
0
        public override int CompareTo(IValuable other)
        {
            var asRoyalFlush = other as RoyalFlush;

            if (asRoyalFlush != null)
            {
                return(CompareTo(asRoyalFlush));
            }

            return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]);
        }
Exemplo n.º 30
0
        public override int CompareTo(IValuable other)
        {
            var asPair = other as Pair;

            if (asPair != null)
            {
                return(CompareTo(asPair));
            }

            return(GlobVars.TypeToValue[this.GetType()] - GlobVars.TypeToValue[other.GetType()]);
        }
Exemplo n.º 31
0
        public void DefaultCollectionValue_GetEntries_FromIValuablesListConstructor()
        {
            DefaultValueProvider <G> valueProvider = new DefaultValueProvider <G>();

            IValuable <G>[] values = new IValuable <G>[] { Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >(), Mock.Of <IValuable <G> >() };

            DefaultArrayMapValue <G> sut = new DefaultArrayMapValue <G>(values, valueProvider);
            List <KeyValuePair <IValuable <G>, ValuePointer <G> > > result = sut.GetEntries();

            Assert.Equal(Enumerable.Range(0, values.Length), result.Select(kv => kv.Key).Cast <IValue>().Select(v => Convert.ToInt32(v.GetData())));
            Assert.Equal(values, result.Select(kv => kv.Value).Select(vp => vp.Value));
            Assert.Equal(Enumerable.Range(0, 6), result.Select(e => e.Value).Cast <EntryValuePointer <G> >().Select(v => v.Index));
        }
Exemplo n.º 32
0
 public SubstituteCaseAction(string columnName, IValuable oldText, IValuable newText)
 {
     ColumnName = columnName;
     OldText = oldText;
     NewText = newText;
 }