MCPcopy Create free account
hub / github.com/cockroachdb/apd / TestQuantize

Function TestQuantize

decimal_test.go:660–703  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

658}
659
660func TestQuantize(t *testing.T) {
661 tests := []struct {
662 s string
663 e int32
664 expect string
665 }{
666 {
667 s: "1.00",
668 e: -1,
669 expect: "1.0",
670 },
671 {
672 s: "2.0",
673 e: -1,
674 expect: "2.0",
675 },
676 {
677 s: "3",
678 e: -1,
679 expect: "3.0",
680 },
681 {
682 s: "9.9999",
683 e: -2,
684 expect: "10.00",
685 },
686 }
687 c := BaseContext.WithPrecision(10)
688 for _, tc := range tests {
689 t.Run(fmt.Sprintf("%s: %d", tc.s, tc.e), func(t *testing.T) {
690 d, _, err := NewFromString(tc.s)
691 if err != nil {
692 t.Fatal(err)
693 }
694 if _, err := c.Quantize(d, d, tc.e); err != nil {
695 t.Fatal(err)
696 }
697 s := d.String()
698 if s != tc.expect {
699 t.Fatalf("expected: %s, got: %s", tc.expect, s)
700 }
701 })
702 }
703}
704
705func TestCmpOrder(t *testing.T) {
706 tests := []struct {

Callers

nothing calls this directly

Calls 5

NewFromStringFunction · 0.85
WithPrecisionMethod · 0.80
RunMethod · 0.80
QuantizeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…