Esempio n. 1
0
func TestSub(t *testing.T) {
	v1 := amount.NewAmount([]quant.Quant{
		{Pillule, 12},
		{Tablette, 2},
		{Boite, 2},
		{Carton, 1},
	}...)

	t.Log(v1.String())

	v2 := amount.NewAmount([]quant.Quant{
		{Pillule, 16},
		{Tablette, 3},
		{Boite, 2},
	}...)

	t.Log(v2.String())

	got := amount.Sub(v1, v2)

	t.Log(got.String())
	t.Log(got.TotalWithRound(Carton))

	exp := amount.NewAmount([]quant.Quant{
		{Pillule, 11},
		{Tablette, 1},
		{Boite, 9},
		{Carton, 0},
	}...)

	ValEqualCheck(t, got, exp)
}
Esempio n. 2
0
// Sub creates a list by subtracting value from right item
// to matching left item, append the non-matching left items
// and append the negative of the right non-matching items
func Sub(ins, subs Items) Items {
	its := ins.Copy()
	for key, sub := range subs {
		if it, ok := its[key]; ok {
			sub.Amount = amount.Sub(it.Amount, sub.Amount)
		} else {
			sub.Amount = sub.Amount.Neg()
		}
		its[key] = sub
	}
	return its
}