func TestGrouperProcJoin(t *testing.T) {
	p1, p2 := 1, 2
	n1, n2 := "g1", "g1"
	starttime := time.Unix(0, 0).UTC()
	tests := []struct {
		procs []IDInfo
		want  GroupByName
	}{
		{
			[]IDInfo{
				piinfo(p1, n1, Counts{1, 2, 3, 4, 5, 6, 0, 0}, Memory{3, 4, 0, 0, 0}, Filedesc{4, 400}, 2),
			},
			GroupByName{
				"g1": Group{Counts{}, States{}, msi{}, 1, Memory{3, 4, 0, 0, 0}, starttime, 4, 0.01, 2, nil},
			},
		}, {
			[]IDInfo{
				piinfost(p1, n1, Counts{3, 4, 5, 6, 7, 8, 0, 0},
					Memory{3, 4, 0, 0, 0}, Filedesc{4, 400}, 2, States{Running: 1}),
				piinfost(p2, n2, Counts{1, 1, 1, 1, 1, 1, 0, 0},
					Memory{1, 2, 0, 0, 0}, Filedesc{40, 400}, 3, States{Sleeping: 1}),
			},
			GroupByName{
				"g1": Group{Counts{2, 2, 2, 2, 2, 2, 0, 0}, States{Running: 1, Sleeping: 1}, msi{}, 2,
					Memory{4, 6, 0, 0, 0}, starttime, 44, 0.1, 5, nil},
			},
		}, {
			[]IDInfo{
				piinfost(p1, n1, Counts{4, 5, 6, 7, 8, 9, 0, 0},
					Memory{1, 5, 0, 0, 0}, Filedesc{4, 400}, 2, States{Running: 1}),
				piinfost(p2, n2, Counts{2, 2, 2, 2, 2, 2, 0, 0},
					Memory{2, 4, 0, 0, 0}, Filedesc{40, 400}, 3, States{Running: 1}),
			},
			GroupByName{
				"g1": Group{Counts{4, 4, 4, 4, 4, 4, 0, 0}, States{Running: 2}, msi{}, 2,
					Memory{3, 9, 0, 0, 0}, starttime, 44, 0.1, 5, nil},
			},
		},
	}
	gr := NewGrouper(newNamer(n1), false, false, false, false)
	for i, tc := range tests {
		got := rungroup(t, gr, procInfoIter(tc.procs...))
		if diff := cmp.Diff(got, tc.want); diff != "" {
			t.Errorf("%d: curgroups differs: (-got +want)\n%s", i, diff)
		}
	}
}
TestGrouperProcJoin tests the appearance of a new process in a group,
and that all procs metrics contribute to a group.
package proc
import (
	"testing"
	"time"
	"github.com/google/go-cmp/cmp"
	"github.com/google/go-cmp/cmp/cmpopts"
)
type grouptest struct {
	grouper *Grouper
	procs   Iter
	want    GroupByName
}
func rungroup(t *testing.T, gr *Grouper, procs Iter) GroupByName {
	_, groups, err := gr.Update(procs)
	if err != nil {
		t.Fatalf("group.Update error: %v", err)
	}
	return groups
}
func TestGrouperBasic(t *testing.T) {
	p1, p2 := 1, 2
	n1, n2 := "g1", "g2"
	starttime := time.Unix(0, 0).UTC()
	tests := []struct {
		procs []IDInfo
		want  GroupByName
	}{
		{
			[]IDInfo{
				piinfost(p1, n1, Counts{1, 2, 3, 4, 5, 6, 0, 0}, Memory{7, 8, 0, 0, 0},
					Filedesc{4, 400}, 2, States{Other: 1}),
				piinfost(p2, n2, Counts{2, 3, 4, 5, 6, 7, 0, 0}, Memory{8, 9, 0, 0, 0},
					Filedesc{40, 400}, 3, States{Waiting: 1}),
			},
			GroupByName{
				"g1": Group{Counts{}, States{Other: 1}, msi{}, 1, Memory{7, 8, 0, 0, 0}, starttime,
					4, 0.01, 2, nil},
				"g2": Group{Counts{}, States{Waiting: 1}, msi{}, 1, Memory{8, 9, 0, 0, 0}, starttime,
					40, 0.1, 3, nil},
			},
		},
		{
			[]IDInfo{
				piinfost(p1, n1, Counts{2, 3, 4, 5, 6, 7, 0, 0},
					Memory{6, 7, 0, 0, 0}, Filedesc{100, 400}, 4, States{Zombie: 1}),
				piinfost(p2, n2, Counts{4, 5, 6, 7, 8, 9, 0, 0},
					Memory{9, 8, 0, 0, 0}, Filedesc{400, 400}, 2, States{Running: 1}),
			},
			GroupByName{
				"g1": Group{Counts{1, 1, 1, 1, 1, 1, 0, 0}, States{Zombie: 1}, msi{}, 1,
					Memory{6, 7, 0, 0, 0}, starttime, 100, 0.25, 4, nil},
				"g2": Group{Counts{2, 2, 2, 2, 2, 2, 0, 0}, States{Running: 1}, msi{}, 1,
					Memory{9, 8, 0, 0, 0}, starttime, 400, 1, 2, nil},
			},
		},
	}
	gr := NewGrouper(newNamer(n1, n2), false, false, false, false)
	for i, tc := range tests {
		got := rungroup(t, gr, procInfoIter(tc.procs...))
		if diff := cmp.Diff(got, tc.want); diff != "" {
			t.Errorf("%d: curgroups differs: (-got +want)\n%s", i, diff)
		}
	}
}