static IntervalTimePerTimeValuesAttribute() { var values = new List<IQuantity>(); var times = new[] { //TODO: ... however, us, ms, s, min, hr, are not unreasonable to expect ... T.Microsecond, T.Millisecond, T.Second, T.Minute, T.Hour, ////TODO: we do not care about Days or Weeks for purposes of these tests... //T.Day, //T.Week, }; // TODO: TBD: Avoid scaling too absurdly: may want to be more selective than this... var length = times.Length - 2; // TODO: TBD: Could also vary the value itself, but this will do for starters... const double value = 1e2; var first = times.Take(length).ToArray(); var second = times.Reverse().Take(length).ToArray(); values.AddRange(from x in first from y in second select new Quantity(value, x, y.Invert())); values.AddRange(from y in first from x in second select new Quantity(value, x, y.Invert())); Values = values.OfType<object>().ToArray(); }
public void EqualityBasedOnNamesAndCount() { string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"}; for (int i = 0; i <= names.Length; ++i) { for (int j = 0; j != 3; ++j) { for (int x = 0; x <= names.Length; ++x) { for (int y = 0; y != 3; ++y) { var info0 = new CallInfo(i + j, names.Take(i)); var info1 = new CallInfo(x + y, names.Take(x)); Assert.Equal(i == x & j == y, info0.Equals(info1)); } } } } }
public void HashCodeBasedOnEquality() { string[] names = new[] {"foo", "bar", "baz", "quux", "quuux"}; for (int i = 0; i <= names.Length; ++i) { for (int j = 0; j != 3; ++j) { for (int x = 0; x <= names.Length; ++x) { for (int y = 0; y != 3; ++y) { var info0 = new CallInfo(i + j, names.Take(i)); var info1 = new CallInfo(x + y, names.Take(x)); if (info0.Equals(info1)) { Assert.Equal(info0.GetHashCode(), info1.GetHashCode()); } else { // Failure at this point is not definitely a bug, // but should be considered a concern unless it can be // convincingly ruled a fluke. Assert.NotEqual(info0.GetHashCode(), info1.GetHashCode()); } } } } } }
public static IEnumerable<ModelEvent> Get(int? take = null) { var project1 = Cuid.Generate(RandomSource.Secure); var player1 = Cuid.Generate(RandomSource.Secure); var player2 = Cuid.Generate(RandomSource.Secure); var player3 = Cuid.Generate(RandomSource.Secure); var player4 = Cuid.Generate(RandomSource.Secure); var feature1 = Cuid.Generate(RandomSource.Secure); var estimate1 = Cuid.Generate(RandomSource.Secure); var estimate2 = Cuid.Generate(RandomSource.Secure); var estimate3 = Cuid.Generate(RandomSource.Secure); var estimate4 = Cuid.Generate(RandomSource.Secure); var estimate5 = Cuid.Generate(RandomSource.Secure); var events = new[] { new ModelEvent { route = new []{ "projects", project1 }, payload = new Payload { values = new { Name = "Project A" }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "players" }, payload = new Payload { values = new Dictionary<string, object> { { player1, new { Name = "Player 1" }.ToDictionary() }, { player2, new { Name = "Player 2" }.ToDictionary() }, { player3, new { Name = "Player 3" }.ToDictionary() }, { player4, new { Name = "Player 4" }.ToDictionary() } } } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1 }, payload = new Payload { values = new { Description = "New feature for project" }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate1 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player1 }, Card = StoryPoints.Points008 }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Points005 }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate3 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player3 }, Card = StoryPoints.Points003 }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate4 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player3 }, Card = StoryPoints.Break }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate5 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player4 }, Card = StoryPoints.DontKnow }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Break, }.ToDictionary() } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates" }, payload = new Payload { delete = new []{ estimate2 } } }, new ModelEvent { route = new []{ "projects", project1, "features", feature1, "estimates", estimate2 }, payload = new Payload { values = new { Player = new [] { "projects", project1, "players", player2 }, Card = StoryPoints.Points013, }.ToDictionary() } }, }; if (take == null) { return events; } return events.Take(take.Value); }
public void WhenInstancesRemoved_ShouldOnlyDistributeAcrossRemainingInstances() { var strategy = new SingleInstanceRoundRobinDistributionStrategy("endpointA", DistributionStrategyScope.Send); var instances = new [] { "1", "2", "3" }; var result = new List<string>(); result.Add(strategy.SelectReceiver(instances)); result.Add(strategy.SelectReceiver(instances)); instances = instances.Take(2).ToArray(); // remove last instance. result.Add(strategy.SelectReceiver(instances)); Assert.That(result.Count, Is.EqualTo(3)); Assert.That(result, Has.Exactly(2).EqualTo(instances[0])); Assert.That(result, Has.Exactly(1).EqualTo(instances[1])); }
public void should_take_first_n_elements_using_take() { var sequence = new[] {1, 2, 3, 4, 5}; IEnumerable<int> filteredElements = sequence.Take(3); // please update variable value to fix the test. IEnumerable<int> expectedResult = new[] {1, 2, 3, 4, 5}; Assert.Equal(expectedResult, filteredElements); }
public void Must_result_in_non_zero() { const string sql = "sql"; IEnumerable<DbParameter> parameters = new[] { new SqlParameter("@Test1", 0), new SqlParameter("@Test2", "Test"), new SqlParameter("@Test3", 1.45m) }; var cacheKey1 = new CacheKey(sql, parameters.Take(1).Skip(1).Take(1)); var cacheKey2 = new CacheKey(sql, parameters); int result = Comparer<CacheKey>.Default.Compare(cacheKey1, cacheKey2); Assert.That(result, Is.EqualTo(-1)); }