Example #1
0
func TestDiff(t *testing.T) {
	v1 := amount.NewAmount([]quant.Quant{
		{Pillule, 12},
		{Tablette, 40},
		{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.Diff(v1, v2)

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

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

	ValEqualCheck(t, got, exp)
}
Example #2
0
func CheckItemsValueAndExistence(t *testing.T, gots items.Items, exps items.Items, name string) {
	for _, exp := range exps {
		got, ok := gots[string(exp.Prod)]
		if !ok {
			t.Errorf("%q does not exist in "+name, exp.Prod)
		}
		if _, no, diff := amount.Diff(got.Amount, exp.Amount); !(no && diff == 0) {
			t.Errorf("not equal")
		}

	}
}
Example #3
0
// Missing creates a list by comparing what is missing in
// the right list : non-existant items from the left list and
// the difference between matching items
// if bigger than 0 or if cannot be compiled as an integer
func Missing(its, exps Items) Items {
	out := map[string]item.Item{}
	for key, exp := range exps {
		if it, ok := its[key]; ok {
			if diff, no, intDiff := amount.Diff(exp.Amount, it.Amount); no && intDiff > 0 {
				out[key] = item.Item{it.Prod, diff}
			}
		} else {
			out[key] = item.Item{exp.Prod, exp.Amount.Copy()}
		}
	}
	return out
}