]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/arrow/csharp/test/Apache.Arrow.Tests/DecimalUtilityTests.cs
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / csharp / test / Apache.Arrow.Tests / DecimalUtilityTests.cs
diff --git a/ceph/src/arrow/csharp/test/Apache.Arrow.Tests/DecimalUtilityTests.cs b/ceph/src/arrow/csharp/test/Apache.Arrow.Tests/DecimalUtilityTests.cs
new file mode 100644 (file)
index 0000000..d235524
--- /dev/null
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one or more
+// contributor license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright ownership.
+// The ASF licenses this file to You under the Apache License, Version 2.0
+// (the "License"); you may not use this file except in compliance with
+// the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+using System;
+using Apache.Arrow.Types;
+using Xunit;
+
+namespace Apache.Arrow.Tests
+{
+    public class DecimalUtilityTests
+    {
+        public class Overflow
+        {
+            [Theory]
+            [InlineData(100.123, 10, 4, false)]
+            [InlineData(100.123, 6, 4, false)]
+            [InlineData(100.123, 3, 3, true)]
+            [InlineData(100.123, 10, 2, true)]
+            [InlineData(100.123, 5, 2, true)]
+            [InlineData(100.123, 5, 3, true)]
+            [InlineData(100.123, 6, 3, false)]
+            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));
+                }
+            }
+        }
+    }
+}