public void ToStringTest() { for (int i = 0; i < 1000; i++) { Item item = new Item { Weight = _Rand.Next(), Value = _Rand.Next() }; Assert.AreEqual(item.ToString(), $"Weight: {item.Weight}, Value: {item.Value}"); } }
public void FindsSolutionTest() { for (int i = 0; i < 10; i++) { List <Item> items = new List <Item>(); for (int j = 0; j < 1000; j++) { Item item = new Item(this._Rand.Next(1, 1000), this._Rand.Next()); items.Add(item); } List <int> weights = items.Select(item => item.Weight).ToList(); int capacity = this._Rand.Next(weights.Min(), weights.Max()); List <int> solution = KnapsackProblem.Solve(capacity, items); int totalUsedCapacity = solution.Sum(s => weights[s]); Assert.IsTrue(totalUsedCapacity <= capacity); } }