Esempio n. 1
0
        public void SimpleTest()
        {
            var distributor = new Distributor(DistributionMethod.FormerPreferred);
            var contract    = new DistributionContract <Ref <int>, Ref <int> >
            {
                Producers      = new Ref <int>[] { 8, 8 },
                ProducerAmount = x => x.Value,
                Consumers      = new Ref <int>[] { 4, 2, 8, 10 },
                ConsumerAmount = x => x.Value,
            };
            var results = distributor.Distribute(contract, out var rests);

            var ps = contract.Producers.Select(x => x.RefValue).ToArray();
            var cs = contract.Consumers.Select(x => x.RefValue).ToArray();

            Assert.Equal(new[] { 4, 2, 2, 6, 2 }, results.Select(x => x.Gain).ToArray());
            foreach (var line in Zipper.Create(new[] { ps[0], ps[0], ps[0], ps[1], ps[1] }, results.Select(x => x.Producer.RefValue).ToArray()))
            {
                Assert.Same(line.Item1, line.Item2);
            }
            foreach (var line in Zipper.Create(new[] { cs[0], cs[1], cs[2], cs[2], cs[3] }, results.Select(x => x.Consumer.RefValue).ToArray()))
            {
                Assert.Same(line.Item1, line.Item2);
            }
            Assert.Equal(0, rests[0].Rest);

            Assert.Same(results[0].Producer.RefValue, ps[0]);
            Assert.NotSame(results[0].Producer.RefValue, ps[1]);
        }
Esempio n. 2
0
        public void ZipperTest()
        {
            var starts = new[] { new DateTime(2018, 6, 15), new DateTime(2018, 12, 31), new DateTime(2019, 1, 1) };
            var ends   = new[] { new DateTime(2018, 7, 15), new DateTime(2019, 1, 1) };

            Assert.Equal(31, Zipper.Create(starts, ends).Sum(x => (x.Item2 - x.Item1).TotalDays));
            Assert.Equal(31, Zipper.Select(starts, ends, (a, b) => b - a).Sum(x => x.TotalDays));
        }
Esempio n. 3
0
        public void Test1()
        {
            var starts = new[] { new DateTime(2018, 6, 15), new DateTime(2018, 12, 31), new DateTime(2019, 1, 1) };
            var ends   = new[] { new DateTime(2018, 7, 15), new DateTime(2019, 1, 1) };

            var linear = Zipper.Create(starts, ends);

            Assert.Equal(31, linear.Sum(x => (x.Item2 - x.Item1).TotalDays));
        }