From 7942b53aee4f415d034fba4e5cca1c23f30aefa2 Mon Sep 17 00:00:00 2001 From: depial <91621102+depial@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:41:36 -0400 Subject: [PATCH] update runtests.jl --- exercises/practice/knapsack/runtests.jl | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/exercises/practice/knapsack/runtests.jl b/exercises/practice/knapsack/runtests.jl index a279c56f..fb0dc81b 100644 --- a/exercises/practice/knapsack/runtests.jl +++ b/exercises/practice/knapsack/runtests.jl @@ -2,10 +2,7 @@ using Test include("knapsack.jl") -struct Item - weight - value -end +Item = NamedTuple{(:weight, :value), Tuple{Int, Int}} @testset verbose = true "tests" begin @testset "no items" begin @@ -13,35 +10,35 @@ end end @testset "one item, too heavy" begin - @test maximum_value(10, [Item(100, 1),]) == 0 + @test maximum_value(10, [Item((100, 1)),]) == 0 end @testset "five items (cannot be greedy by weight)" begin - items = [Item(2, 5), Item(2, 5), Item(2, 5), Item(2, 5), Item(10, 21)] + items = [Item((2, 5)), Item((2, 5)), Item((2, 5)), Item((2, 5)), Item((10, 21))] @test maximum_value(10, items) == 21 end @testset "five items (cannot be greedy by value)" begin - items = [Item(2, 20), Item(2, 20), Item(2, 20), Item(2, 20), Item(10, 50)] + items = [Item((2, 20)), Item((2, 20)), Item((2, 20)), Item((2, 20)), Item((10, 50))] @test maximum_value(10, items) == 80 end @testset "example knapsack" begin - items = [Item(5, 10), Item(4, 40), Item(6, 30), Item(4, 50)] + items = [Item((5, 10)), Item((4, 40)), Item((6, 30)), Item((4, 50))] @test maximum_value(10, items) == 90 end @testset "8 items" begin - items = [Item(25, 350), Item(35, 400), Item(45, 450), Item(5, 20), - Item(25, 70), Item(3, 8), Item(2, 5), Item(2, 5)] + items = [Item((25, 350)), Item((35, 400)), Item((45, 450)), Item((5, 20)), + Item((25, 70)), Item((3, 8)), Item((2, 5)), Item((2, 5))] @test maximum_value(104, items) == 900 end @testset "15 items" begin - items = [Item(70, 135), Item(73, 139), Item(77, 149), Item(80, 150), - Item(82, 156), Item(87, 163), Item(90, 173), Item(94, 184), - Item(98, 192), Item(106, 201), Item(110, 210), Item(113, 214), - Item(115, 221), Item(118, 229), Item(120, 240)] + items = [Item((70, 135)), Item((73, 139)), Item((77, 149)), Item((80, 150)), + Item((82, 156)), Item((87, 163)), Item((90, 173)), Item((94, 184)), + Item((98, 192)), Item((106, 201)), Item((110, 210)), Item((113, 214)), + Item((115, 221)), Item((118, 229)), Item((120, 240))] @test maximum_value(750, items) == 1458 end end