public void TestDeltaValueOperatorForDecodingIntegerValue() { Assert.AreEqual(new IntegerValue(45), OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeValue(new IntegerValue(15), new IntegerValue(30), null)); Assert.AreEqual(new IntegerValue(30), OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeValue(new IntegerValue(-15), new IntegerValue(45), null)); var field = new Scalar("", FastType.I32, Operator.Delta, new IntegerValue(25), false); Assert.AreEqual(new IntegerValue(30), OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeValue(new IntegerValue(5), ScalarValue.Undefined, field)); var field2 = new Scalar("", FastType.I32, Operator.Delta, new IntegerValue(25), false); Assert.AreEqual(new IntegerValue(25), OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeEmptyValue( ScalarValue.Undefined, field2)); Assert.AreEqual(new IntegerValue(5), OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeEmptyValue(new IntegerValue(5), field)); var field1 = new Scalar("", FastType.I32, Operator.Delta, ScalarValue.Undefined, true); Assert.AreEqual(ScalarValue.Undefined, OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeEmptyValue( ScalarValue.Undefined, field1)); }
public void TestGetValueToEncodeForOptional() { var field = new Scalar("", FastType.Decimal, Operator.Delta, ScalarValue.Undefined, true); OperatorCodec operatortemp = field.OperatorCodec; var value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.55), ScalarValue.Undefined, field); Assert.AreEqual(new decimal(9427.55), value.ToBigDecimal()); value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.51), Decimal(9427.55), field); Assert.AreEqual(-4, (int)value.Mantissa); Assert.AreEqual(0, (int)value.Exponent); value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(9427.46), Decimal(9427.51), field); Assert.AreEqual(-5, (int)value.Mantissa); Assert.AreEqual(0, (int)value.Exponent); value = (DecimalValue)operatortemp.GetValueToEncode(Decimal(30.6), Decimal(30.6), field); Assert.AreEqual(0, (int)value.Exponent); Assert.AreEqual(0, (int)value.Mantissa); Assert.AreEqual(ScalarValue.Null, operatortemp.GetValueToEncode(null, Decimal(30.6), field)); }
public void TestDeltaOperatorForOptionalUnsignedInteger() { var field = new Scalar("", FastType.U32, Operator.Delta, ScalarValue.Undefined, true); OperatorCodec delta = field.OperatorCodec; Assert.AreEqual(ScalarValue.Null, delta.GetValueToEncode(null, ScalarValue.Undefined, field)); }
public void TestCopyOperator() { var field = new Scalar("", FastType.U32, Operator.Copy, ScalarValue.Undefined, true); OperatorCodec copy = Operator.Copy.GetCodec(FastType.U32); Assert.AreEqual(new IntegerValue(1), copy.GetValueToEncode(new IntegerValue(1), null, field)); Assert.AreEqual(new IntegerValue(2), copy.GetValueToEncode(new IntegerValue(2), new IntegerValue(1), field)); //newly added implementation Assert.AreEqual(null, copy.GetValueToEncode(ScalarValue.Null, ScalarValue.Null, field)); }
protected static void AssertScalarField(IFieldSet fieldSet, int fieldIndex, FastType type, String name, OperatorCodec operatorCodec, ScalarValue defaultValue) { var field = (Scalar)fieldSet.GetField(fieldIndex); AssertScalarField(field, type, name); Assert.AreEqual(operatorCodec, field.OperatorCodec); Assert.AreEqual(defaultValue, field.DefaultValue); }
public Scalar(Scalar other) : base(other) { _defaultValue = (ScalarValue)other._defaultValue.Clone(); _fastType = other._fastType; _initialValue = (ScalarValue)other._initialValue.Clone(); _operator = other._operator; _operatorCodec = other._operatorCodec; _typeCodec = other._typeCodec; _dictionary = other._dictionary; }
public void TestIncrementOperatorWithNoDefaultValue() { var field = new Scalar("", FastType.U32, Operator.Increment, ScalarValue.Undefined, false); Assert.AreEqual(new IntegerValue(1), OperatorCodec.GetCodec(Operator.Increment, FastType.I32).GetValueToEncode( new IntegerValue(1), null, field)); Assert.AreEqual(null, OperatorCodec.GetCodec(Operator.Increment, FastType.I32).GetValueToEncode( new IntegerValue(2), new IntegerValue(1), field)); }
private Scalar(QName name, FastType fastType, Operator op, OperatorCodec operatorCodec, ScalarValue defaultValue, bool optional) : base(name, optional) { _operator = op; _operatorCodec = operatorCodec; _dictionary = DictionaryFields.Global; _defaultValue = defaultValue ?? ScalarValue.Undefined; _fastType = fastType; _typeCodec = fastType.GetCodec(op, optional); _initialValue = (defaultValue == null || defaultValue.IsUndefined) ? _fastType.DefaultValue : defaultValue; op.Validate(this); }
public void TestDecodeForMandatoryFieldAndDefaultValue() { var field = new Scalar("", FastType.Decimal, Operator.Delta, Decimal(12000), false); Assert.AreEqual(Decimal(12000), OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeEmptyValue(ScalarValue.Undefined, field)); Assert.AreEqual(Decimal(12100), OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(109, -1), Decimal(12000), field)); Assert.AreEqual(Decimal(12150), OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(1094, -1), Decimal(12100), field)); Assert.AreEqual(Decimal(12200), OperatorCodec.GetCodec(Operator.Delta, FastType.Decimal).DecodeValue(Decimal(-1093, 1), Decimal(12150), field)); }
public void TestDeltaValueOperatorForDecodingIntegerValueWithEmptyPriorValue() { try { var field = new Scalar("", FastType.U32, Operator.Delta, new IntegerValue(25), false); OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeValue(new IntegerValue(30), null, field); //newly added implementation var field1 = new Scalar("", FastType.U32, Operator.Delta, ScalarValue.Undefined, false); Assert.AreEqual(ScalarValue.Undefined, OperatorCodec.GetCodec(Operator.Delta, FastType.I32).DecodeEmptyValue( ScalarValue.Undefined, field1)); Assert.Fail(); } catch (DynErrorException e) { Assert.AreEqual(DynError.MandatoryFieldNotPresent, e.Error); } }
public Scalar(QName name, FastType fastType, OperatorCodec operatorCodec, ScalarValue defaultValue, bool optional) : this(name, fastType, operatorCodec.Operator, operatorCodec, defaultValue, optional) { }