public void WeightedRoutees_should_allocate_weighted_local_routees() { var weights = new Dictionary <Address, int>() { [_a1] = 2, [_b1] = 1, [_c1] = 10 }.ToImmutableDictionary(); var routees2 = ImmutableArray.Create <Routee>(_testActorRoutee, _routeeB, _routeeC); var weighted = new WeightedRoutees(routees2, _a1, weights); Range(1, 2).ForEach(i => weighted[i].Should().Be(_testActorRoutee)); Range(3, weighted.Total).ForEach(i => weighted[i].Should().NotBe(_testActorRoutee)); }
public void WeightedRoutees_should_allocate_routees_for_undefined_weight() { var weights = new Dictionary <Address, int>() { [_a1] = 1, [_b1] = 7, }.ToImmutableDictionary(); var weighted = new WeightedRoutees(_routees, _a1, weights); weighted[1].Should().Be(_routeeA); Range(2, 8).ForEach(i => weighted[i].Should().Be(_routeeB)); // undefined, uses the mean of the weights, i.e. 4 Range(9, 12).ForEach(i => weighted[i].Should().Be(_routeeC)); weighted.Total.Should().Be(12); }
public void WeightedRoutees_should_allocate_weighted_routes() { var weights = new Dictionary <Address, int>() { [_a1] = 1, [_b1] = 3, [_c1] = 10 }.ToImmutableDictionary(); var weighted = new WeightedRoutees(_routees, _a1, weights); weighted[1].Should().Be(_routeeA); Range(2, 4).ForEach(i => weighted[i].Should().Be(_routeeB)); Range(5, 14).ForEach(i => weighted[i].Should().Be(_routeeC)); weighted.Total.Should().Be(14); }
public void WeightedRoutees_should_check_boundaries() { var empty = new WeightedRoutees(ImmutableArray <Routee> .Empty, _a1, ImmutableDictionary <Address, int> .Empty); empty.IsEmpty.Should().BeTrue(); empty.Invoking(e => _ = e.Total).Should().Throw <IllegalStateException>(); var empty2 = new WeightedRoutees(ImmutableArray.Create <Routee>(_routeeA), _a1, ImmutableDictionary <Address, int> .Empty.Add(_a1, 0)); empty2.IsEmpty.Should().BeTrue(); empty2.Invoking(e => _ = e.Total).Should().Throw <IllegalStateException>(); empty2.Invoking(e => _ = e[0]).Should().Throw <IllegalStateException>(); var weighted = new WeightedRoutees(_routees, _a1, ImmutableDictionary <Address, int> .Empty); weighted.Total.Should().Be(3); weighted.Invoking(e => _ = e[0]).Should().Throw <ArgumentException>(); weighted.Invoking(e => _ = e[4]).Should().Throw <ArgumentException>(); }