示例#1
0
func TestAddVal(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{
		{Tablette, 3},
		{Boite, 2},
	}...)

	t.Log(v2.String())

	got := amount.Add(v1, v2)

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

	exp := amount.NewAmount([]quant.Quant{
		{Pillule, 12},
		{Tablette, 5},
		{Boite, 4},
		{Carton, 1},
	}...)

	ValEqualCheck(t, got, exp)
}
示例#2
0
// Add creates a list by adding value of each matching item
// and then apprend the non-matching one
func Add(ins, adds Items) Items {
	its := ins.Copy()
	for key, add := range adds {
		if it, ok := its[key]; ok {
			add.Amount = amount.Add(it.Amount, add.Amount)
		}
		its[key] = add
	}
	return its
}