public void GetChannelsShouldReturnAllChannelsLinkedWithCurrentNode() { // Arrange CreateTwoNodesForTests(); CreateChannelForTests(); // Act var result = _network.GetChannels(_channel.FirstNodeId); // Assert Assert.That(result.Count, Is.EqualTo(1)); Assert.IsTrue(result.Any(c => c.SecondNodeId == _channel.SecondNodeId || c.FirstNodeId == _channel.SecondNodeId)); }
private int GetNumberOfChannels(Node node) { var roundedPower = (int)Math.Ceiling(_networkPower); var currentChannelsNumber = _network.Channels.Length; var maxChannelsCountInNode = MaxChannelsCountInNode(node); var nodesWithChannelsCount = _network.Nodes .Select(n => _network.GetChannels(n.Id)) .Count(c => c.Length != 0); var currentNodePower = 2 * currentChannelsNumber / (double)nodesWithChannelsCount; int numberOfChannels; if (_network.Channels.Length == 0 || Math.Abs(_networkPower - currentNodePower) < AllConstants.Eps) { numberOfChannels = AllConstants.RandomGenerator.Next(roundedPower) + 1; } else { numberOfChannels = nodesWithChannelsCount * roundedPower - 2 * currentChannelsNumber; if (numberOfChannels < 0) { numberOfChannels = 0; } } if (numberOfChannels > maxChannelsCountInNode) { numberOfChannels = maxChannelsCountInNode; } return(numberOfChannels); }