mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Coverage tests for utils
This commit is contained in:
committed by
Dan Christian Bogos
parent
323046e416
commit
4d568cb498
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
@@ -378,13 +377,10 @@ func TestAppend2(t *testing.T) {
|
||||
dn.Type = NMMapType
|
||||
dn.Slice = nil
|
||||
dn.Map = map[string]*DataNode{}
|
||||
dnExpect := NewDataNode(testPath)
|
||||
|
||||
if _, err := dn.Append(testPath, val1); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
fmt.Println(ToJSON(dn.Map["0"]))
|
||||
fmt.Println(ToJSON(dnExpect))
|
||||
|
||||
///
|
||||
dn.Type = NMSliceType
|
||||
|
||||
@@ -20,6 +20,7 @@ package utils
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/ericlagergren/decimal"
|
||||
@@ -173,3 +174,35 @@ func TestDecimalNewDecimalFromStringFail(t *testing.T) {
|
||||
t.Errorf("\nExpected: <%+v>, \nReceived: <%+v>", expected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDivideBigWithReminder(t *testing.T) {
|
||||
x := new(decimal.Big).SetUint64(10)
|
||||
y := new(decimal.Big).SetUint64(5)
|
||||
qExpected := new(decimal.Big).SetUint64(2)
|
||||
rExpected := new(decimal.Big).SetUint64(0)
|
||||
qReceived, rReceived := DivideBigWithReminder(x, y)
|
||||
if !reflect.DeepEqual(qExpected, qReceived) {
|
||||
t.Errorf("Expected divident <+%v> but received <+%v>", qExpected, qReceived)
|
||||
} else if !reflect.DeepEqual(rExpected, rReceived) {
|
||||
t.Errorf("Expected divident <+%v> but received <+%v>", rExpected, rReceived)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDecimalFromFloat64(t *testing.T) {
|
||||
x := 21.5
|
||||
xExp, _ := new(decimal.Big).SetString(strconv.FormatFloat(x, 'f', -1, 64))
|
||||
expected := &Decimal{xExp}
|
||||
// fmt.Printf("%v of type %T", expected, expected)
|
||||
rcv := NewDecimalFromFloat64(x)
|
||||
if !reflect.DeepEqual(rcv, expected) {
|
||||
t.Errorf("Expected <+%v> but received <+%v>", xExp, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecimalClone(t *testing.T) {
|
||||
d := &Decimal{new(decimal.Big).SetUint64(3)}
|
||||
rcv := d.Clone()
|
||||
if !reflect.DeepEqual(d, rcv) {
|
||||
t.Errorf("Expected <+%v> but received <+%v>", d, rcv)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,14 @@ func TestNewDynamicWeightsFromString(t *testing.T) {
|
||||
} else if !reflect.DeepEqual(eDws, dws) {
|
||||
t.Errorf("expecting: %+v, received: %+v", ToJSON(eDws), ToJSON(dws))
|
||||
}
|
||||
|
||||
///
|
||||
dwsStr = "fltr1&fltr2;20;30;fltr3;30;fltr4&fltr5;50"
|
||||
expected := "invalid DynamicWeight format for string <fltr1&fltr2;20;30;fltr3;30;fltr4&fltr5;50>"
|
||||
if _, err := NewDynamicWeightsFromString(dwsStr, ";", "&"); err == nil || err.Error() != expected {
|
||||
t.Errorf("expecting: %+v, received: %+v", expected, err)
|
||||
}
|
||||
|
||||
eDws = DynamicWeights{
|
||||
{
|
||||
FilterIDs: []string{"fltr1", "fltr2"},
|
||||
@@ -86,7 +94,7 @@ func TestNewDynamicWeightsFromString(t *testing.T) {
|
||||
}
|
||||
|
||||
dwsStr = "fltr1&fltr2;not_a_float64"
|
||||
expected := "invalid Weight <not_a_float64> in string: <fltr1&fltr2;not_a_float64>"
|
||||
expected = "invalid Weight <not_a_float64> in string: <fltr1&fltr2;not_a_float64>"
|
||||
if _, err := NewDynamicWeightsFromString(dwsStr, ";", "&"); err == nil || err.Error() != expected {
|
||||
t.Errorf("expecting: %+v, received: %+v", expected, err)
|
||||
}
|
||||
|
||||
@@ -870,3 +870,20 @@ func TestOrderedNavigableMapOrderedFields(t *testing.T) {
|
||||
t.Errorf("Expected %+v, received %+v", exp2, rcv2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetAsSliceErr(t *testing.T) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
err := nm.SetAsSlice(&FullPath{}, []*DataNode{NewLeafNode(10), NewLeafNode(101)})
|
||||
if err == nil || err != ErrWrongPath {
|
||||
t.Errorf("Expected %+v, received %+v", ErrWrongPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFieldAsString(t *testing.T) {
|
||||
nm := NewOrderedNavigableMap()
|
||||
path := []string{"0", "path"}
|
||||
_, err := nm.FieldAsString(path)
|
||||
if err == nil || err != ErrNotFound {
|
||||
t.Errorf("Expected %+v, received %+v", ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user