Skip to content
Snippets Groups Projects
KnapsackProblemTest.cs 1.19 KiB
Newer Older
Vesa Lappalainen's avatar
Vesa Lappalainen committed
// ReSharper disable all
using System;
using System.Collections.Generic;
using NUnit.Framework;
using static KnapsackProblem;
using System.Linq;

	[TestFixture]
	[DefaultFloatingPointTolerance(0.000001)]
	public  class TestKnapsackProblem
	{
		[Test]
		public  void Teststatic47()
		{
			Item[] items = {
			new Item("micro", 8, 50),
			new Item("drone", 2, 150),
			new Item("monitor", 6, 210),
			new Item("kettle", 1, 30)
			};
			(long bestValue, List<Item> used) = KnapsackBruteForce(items, 10);
			Assert.AreEqual( 390, bestValue , "in method static, line 58");
			Assert.AreEqual(( "drone, monitor, kettle").ToString(), String.Join(", ", used.Select(item => item.name) ), "in method static, line 59");
			(bestValue, used) = KnapsackBruteForce(items, 8);
			Assert.AreEqual( 360, bestValue , "in method static, line 61");
			Assert.AreEqual(( "drone, monitor").ToString(), String.Join(", ", used.Select(item => item.name) ), "in method static, line 62");
			(bestValue, used) = KnapsackBruteForce(items, 3);
			Assert.AreEqual( 180, bestValue , "in method static, line 64");
			Assert.AreEqual(( "drone, kettle").ToString(), String.Join(", ", used.Select(item => item.name) ), "in method static, line 65");
		}
	}