zeroshade commented on code in PR #13792:
URL: https://github.com/apache/arrow/pull/13792#discussion_r938023186


##########
go/arrow/array/decimal256_test.go:
##########
@@ -0,0 +1,179 @@
+// 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.
+
+package array_test
+
+import (
+       "testing"
+
+       "github.com/apache/arrow/go/v10/arrow"
+       "github.com/apache/arrow/go/v10/arrow/array"
+       "github.com/apache/arrow/go/v10/arrow/decimal256"
+       "github.com/apache/arrow/go/v10/arrow/memory"
+       "github.com/stretchr/testify/assert"
+)
+
+func TestNewDecimal256Builder(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+       defer mem.AssertSize(t, 0)
+
+       ab := array.NewDecimal256Builder(mem, &arrow.Decimal256Type{Precision: 
10, Scale: 1})
+       defer ab.Release()
+
+       ab.Retain()
+       ab.Release()
+
+       want := []decimal256.Num{
+               decimal256.New(1, 1, 1, 1),
+               decimal256.New(2, 2, 2, 2),
+               decimal256.New(3, 3, 3, 3),
+               {},
+               decimal256.FromI64(-5),
+               decimal256.FromI64(-6),
+               {},
+               decimal256.FromI64(8),
+               decimal256.FromI64(9),
+               decimal256.FromI64(10),
+       }
+       valids := []bool{true, true, true, false, true, true, false, true, 
true, true}
+
+       for i, valid := range valids {
+               switch {
+               case valid:
+                       ab.Append(want[i])
+               default:
+                       ab.AppendNull()
+               }
+       }
+
+       // check state of builder before NewDecimal256Array
+       assert.Equal(t, 10, ab.Len(), "unexpected Len()")
+       assert.Equal(t, 2, ab.NullN(), "unexpected NullN()")
+
+       a := ab.NewArray().(*array.Decimal256)
+       a.Retain()
+       a.Release()
+
+       // check state of builder after NewDecimal256Array
+       assert.Zero(t, ab.Len(), "unexpected ArrayBuilder.Len(), 
NewDecimal256Array did not reset state")
+       assert.Zero(t, ab.Cap(), "unexpected ArrayBuilder.Cap(), 
NewDecimal256Array did not reset state")
+       assert.Zero(t, ab.NullN(), "unexpected ArrayBuilder.NullN(), 
NewDecimal256Array did not reset state")
+
+       // check state of array
+       assert.Equal(t, 2, a.NullN(), "unexpected null count")
+
+       assert.Equal(t, want, a.Values(), "unexpected Decimal256Values")
+       assert.Equal(t, []byte{0xb7}, a.NullBitmapBytes()[:1]) // 4 bytes due 
to minBuilderCapacity
+       assert.Len(t, a.Values(), 10, "unexpected length of Decimal256Values")
+
+       a.Release()
+       ab.Append(decimal256.FromI64(7))
+       ab.Append(decimal256.FromI64(8))
+
+       a = ab.NewDecimal256Array()
+
+       assert.Equal(t, 0, a.NullN())
+       assert.Equal(t, []decimal256.Num{decimal256.FromI64(7), 
decimal256.FromI64(8)}, a.Values())
+       assert.Len(t, a.Values(), 2)

Review Comment:
   for reference, they *are* tested in the new tests I added in 
`decimal_test.go` but I'll also add those assertions here too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to