Beispiel #1
0
    public void TestCase2()
    {
        // Total Value = 150
        // Total Wight = 190
        // Item with vi 50 and weight 75
        //              50            59
        //              50            56

        // Arrange
        FileReader fileReader = new FileReader();

        (int, Item[])extractedValues = fileReader.ExtractItems(@"C:\Users\Paul\Documents\Open Source Society for Computer Science (OSSU)\Algorithms Coursera\Programming Assignments\Week 12 Programming Assignment\TestCase\testcase2.txt");
        List <int> indices;

        // Act
        KnapSack knapSack = new KnapSack(extractedValues.Item2, extractedValues.Item1);

        indices = knapSack.Reconstruction();

        // Assert
        Assert.Equal(150, knapSack.GetOptimalSackValue());
        Assert.Equal(4, indices[0]);
        Assert.Equal(1, indices[1]);
        Assert.Equal(0, indices[2]);

        int totalWeight = 0;

        foreach (int ind in indices)
        {
            totalWeight += extractedValues.Item2[ind]._weight;
        }

        Assert.Equal(190, totalWeight);
    }
Beispiel #2
0
    public void TestCase1()
    {
        // Expected Result 14
        // Arrange
        FileReader fileReader = new FileReader();

        (int, Item[])extractedValues = fileReader.ExtractItems(@"C:\Users\Paul\Documents\Open Source Society for Computer Science (OSSU)\Algorithms Coursera\Programming Assignments\Week 12 Programming Assignment\TestCase\testcase1.txt");

        // Act
        KnapSack knapSack = new KnapSack(extractedValues.Item2, extractedValues.Item1);

        // Assert
        Assert.Equal(14, knapSack.GetOptimalSackValue());
    }