public void AppendInvalidPrecisionAndScaleDecimal() { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(2, 1)); // Assert Assert.Throws <OverflowException>(() => builder.Append(100)); Assert.Throws <OverflowException>(() => builder.Append(0.01M)); builder.Append(-9.9M); builder.Append(0); builder.Append(9.9M); }
public void Encode(object row) { var val = _getFunc(row); if (_nullable && val == null) { _builder.AppendNull(); } else { _builder.Append((decimal)val); } }
public void AppendClearAppendDecimal() { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(24, 8)); // Act builder.Append(1); builder.Clear(); builder.Append(10); // Assert var array = builder.Build(); Assert.Equal(10, array.GetValue(0)); }
public void HasExpectedResultOrThrows(decimal d, int precision, int scale, bool shouldThrow) { var builder = new Decimal128Array.Builder(new Decimal128Type(precision, scale)); if (shouldThrow) { Assert.Throws <OverflowException>(() => builder.Append(d)); } else { builder.Append(d); var result = builder.Build(new TestMemoryAllocator()); Assert.Equal(d, result.GetValue(0)); } }
public void AppendLargeDecimal() { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(26, 2)); decimal large = 999999999999909999999999.80M; // Act builder.Append(large); builder.Append(-large); // Assert var array = builder.Build(); Assert.Equal(large, array.GetValue(0)); Assert.Equal(-large, array.GetValue(1)); }
public void AppendDecimal(int count) { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(14, 10)); // Act decimal?[] testData = new decimal?[count]; for (int i = 0; i < count; i++) { if (i == count - 2) { builder.AppendNull(); testData[i] = null; continue; } decimal rnd = i * (decimal)Math.Round(new Random().NextDouble(), 10); testData[i] = rnd; builder.Append(rnd); } // Assert var array = builder.Build(); Assert.Equal(count, array.Length); for (int i = 0; i < count; i++) { Assert.Equal(testData[i], array.GetValue(i)); } }
public void SetDecimal() { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(24, 8)); // Act builder.Append(123.45M); builder.Append(678.9M); builder.Swap(0, 1); // Assert var array = builder.Build(); Assert.Equal(678.9M, array.GetValue(0)); Assert.Equal(123.45M, array.GetValue(1)); }
public void AppendFractionalDecimal() { // Arrange var builder = new Decimal128Array.Builder(new Decimal128Type(26, 20)); decimal fraction = 0.99999999999990999992M; // Act builder.Append(fraction); builder.Append(-fraction); // Assert var array = builder.Build(); Assert.Equal(fraction, array.GetValue(0)); Assert.Equal(-fraction, array.GetValue(1)); }
public void Visit(Decimal128Type type) { Decimal128Array.Builder resultBuilder = new Decimal128Array.Builder(type).Reserve(_baseDataTotalElementCount); for (int i = 0; i < _baseDataListCount; i++) { List <int?> dataList = _baseData[i]; Decimal128Array.Builder builder = new Decimal128Array.Builder(type).Reserve(dataList.Count); foreach (decimal?value in dataList) { if (value.HasValue) { builder.Append(value.Value); resultBuilder.Append(value.Value); } else { builder.AppendNull(); resultBuilder.AppendNull(); } } TestTargetArrayList.Add(builder.Build()); } ExpectedArray = resultBuilder.Build(); }
public void Visit(Decimal128Type type) { var builder = new Decimal128Array.Builder(type).Reserve(Length); for (var i = 0; i < Length; i++) { builder.Append((decimal)i / Length); } Array = builder.Build(); }