Skip to content

Commit c7c84e8

Browse files
committed
add oct_test.go
1 parent 6ea7cd5 commit c7c84e8

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

sql/expression/function/oct_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,79 @@
1+
// Copyright 2025 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
package function
16+
17+
import (
18+
"github.com/dolthub/go-mysql-server/sql"
19+
"github.com/dolthub/go-mysql-server/sql/expression"
20+
"github.com/dolthub/go-mysql-server/sql/types"
21+
"math"
22+
"testing"
23+
)
24+
25+
type test struct {
26+
name string
27+
nType sql.Type
28+
row sql.Row
29+
expected interface{}
30+
}
31+
32+
func TestOct(t *testing.T) {
33+
tests := []test{
34+
// NULL input
35+
{"n is nil", types.Int32, sql.NewRow(nil), nil},
36+
37+
// Positive numbers
38+
{"positive small", types.Int32, sql.NewRow(8), "10"},
39+
{"positive medium", types.Int32, sql.NewRow(64), "100"},
40+
{"positive large", types.Int32, sql.NewRow(4095), "7777"},
41+
{"positive huge", types.Int64, sql.NewRow(123456789), "726746425"},
42+
43+
// Negative numbers
44+
{"negative small", types.Int32, sql.NewRow(-8), "1777777777777777777770"},
45+
{"negative medium", types.Int32, sql.NewRow(-64), "1777777777777777777700"},
46+
{"negative large", types.Int32, sql.NewRow(-4095), "1777777777777777770001"},
47+
48+
// Zero
49+
{"zero", types.Int32, sql.NewRow(0), "0"},
50+
51+
// String inputs
52+
{"string number", types.LongText, sql.NewRow("15"), "17"},
53+
{"alpha string", types.LongText, sql.NewRow("abc"), "0"},
54+
{"mixed string", types.LongText, sql.NewRow("123abc"), "173"},
55+
56+
// Edge cases
57+
{"max int32", types.Int32, sql.NewRow(math.MaxInt32), "17777777777"},
58+
{"min int32", types.Int32, sql.NewRow(math.MinInt32), "1777777777760000000000"},
59+
{"max int64", types.Int64, sql.NewRow(math.MaxInt64), "777777777777777777777"},
60+
{"min int64", types.Int64, sql.NewRow(math.MinInt64), "1000000000000000000000"},
61+
62+
// Decimal numbers
63+
{"decimal", types.Float64, sql.NewRow(15.5), "17"},
64+
{"negative decimal", types.Float64, sql.NewRow(-15.5), "1777777777777777777761"},
65+
}
66+
67+
for _, tt := range tests {
68+
t.Run(tt.name, func(t *testing.T) {
69+
f := NewOct(expression.NewGetField(0, tt.nType, "n", true))
70+
result, err := f.Eval(sql.NewEmptyContext(), tt.row)
71+
if err != nil {
72+
t.Fatal(err)
73+
}
74+
if result != tt.expected {
75+
t.Errorf("got %v; expected %v", result, tt.expected)
76+
}
77+
})
78+
}
79+
}

0 commit comments

Comments
 (0)