Beispiel #1
0
        public void Sample_on_targetgroups()
        {
            var population = new []
            {
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG1"
                },
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG1"
                },
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG1"
                },
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG2"
                },
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG2"
                },
                new Unit {
                    Id = "*****@*****.**", TargetGroup = "TG2"
                }
            };

            var targetGroups = new []
            {
                new TargetGroup {
                    Id = "TG1", SampleSize = 2
                },
                new TargetGroup {
                    Id = "TG2", SampleSize = 2
                }
            };

            var sampler = new Sampler();
            var sample  = sampler.CreateSampleForTargetGroups(population, targetGroups);

            // TG1 should have 2 units sampled
            // TG2 should have 2 units sampled
            sample.Length.ShouldBe(4);
            sample.Count(x => x.TargetGroup == "TG1").ShouldBe(2);
            sample.Count(x => x.TargetGroup == "TG2").ShouldBe(2);
        }