Skip to content
Snippets Groups Projects
Select Git revision
  • 0e6bc2859d6ee7a437503fc30f7bea20e322c26f
  • main default protected
  • melissa
  • yanis
  • variant
5 results

Scenario.java

Blame
  • Forked from COUETOUX Basile / FirefighterStarter
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    BackPackSolverTest.java 994 B
    package fr.univamu.progav.td2;
    
    import org.junit.jupiter.api.Test;
    
    import java.util.List;
    
    import static org.junit.jupiter.api.Assertions.*;
    
    class BackPackSolverTest {
    
    
      private final static List<BackPackSolver.Item> ITEMS =
        List.of(
          new BackPackSolver.Item("Alfa",5,8),
          new BackPackSolver.Item("Bravo",4,7),
          new BackPackSolver.Item("Charlie",4,6),
          new BackPackSolver.Item("Delta",3,4),
          new BackPackSolver.Item("Echo",2,3)
        );
      public static final int AVAILABLE_VOLUME = 10;
    
      @Test
      void findBestValueBackpack() {
        BackPackSolver bp = new BackPackSolver(ITEMS, AVAILABLE_VOLUME);
        List<BackPackSolver.Item> selection = bp.findBestValueBackpack(0);
        int totalVolume = selection.stream().mapToInt(BackPackSolver.Item::volume).sum();
        int totalValue = selection.stream().mapToInt(BackPackSolver.Item::value).sum();
        assertTrue(totalVolume <= AVAILABLE_VOLUME);
        assertEquals(16,totalValue);
        assertEquals(3,selection.size());
      }
    }