1// Copyright 2016 The Cockroach Authors.
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
12// implied. See the License for the specific language governing
13// permissions and limitations under the License.
14
15package apd
16
17import "testing"
18
19// Appease the unused test.
20// TODO(mjibson): actually test all the ErrDecimal methods.
21func TestErrDecimal(t *testing.T) {
22	ed := MakeErrDecimal(testCtx)
23	a := New(1, 0)
24	ed.Abs(a, a)
25	ed.Exp(a, a)
26	ed.Ln(a, a)
27	ed.Log10(a, a)
28	ed.Neg(a, a)
29	ed.Pow(a, a, a)
30	ed.QuoInteger(a, a, a)
31	ed.Rem(a, a, a)
32	ed.Round(a, a)
33}
34
35// TestMakeErrDecimalWithPrecision tests that WithPrecision generates a copy
36// and not a reference.
37func TestMakeErrDecimalWithPrecision(t *testing.T) {
38	c := &Context{
39		Precision:   5,
40		MaxExponent: 2,
41	}
42	nc := c.WithPrecision(c.Precision * 2)
43	ed := MakeErrDecimal(nc)
44	if ed.Ctx.Precision != 10 {
45		t.Fatalf("expected %d, got %d", 10, ed.Ctx.Precision)
46	}
47	if c.Precision != 5 {
48		t.Fatalf("expected %d, got %d", 5, c.Precision)
49	}
50	if c.MaxExponent != 2 {
51		t.Fatalf("expected %d, got %d", 2, c.MaxExponent)
52	}
53}
54