github.com/dds/aoc2020@v1.9.84/day7/day7_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/dds/aoc2020/lib"
     8  	"github.com/stretchr/testify/require"
     9  )
    10  
    11  func BenchmarkPart1(*testing.B) {
    12  	part1(Input)
    13  }
    14  func BenchmarkPart2(*testing.B) {
    15  	part2(Input)
    16  }
    17  
    18  func TestPart1(t *testing.T) {
    19  	type test struct {
    20  		input  string
    21  		expect int
    22  	}
    23  
    24  	tests := []test{
    25  		test{
    26  			input: `light red bags contain 1 bright white bag, 2 muted yellow bags.
    27  dark orange bags contain 3 bright white bags, 4 muted yellow bags.
    28  bright white bags contain 1 shiny gold bag.
    29  muted yellow bags contain 2 shiny gold bags, 9 faded blue bags.
    30  shiny gold bags contain 1 dark olive bag, 2 vibrant plum bags.
    31  dark olive bags contain 3 faded blue bags, 4 dotted black bags.
    32  vibrant plum bags contain 5 faded blue bags, 6 dotted black bags.
    33  faded blue bags contain no other bags.
    34  dotted black bags contain no other bags.`,
    35  			expect: 4,
    36  		},
    37  	}
    38  
    39  	for i, test := range tests {
    40  		t.Run(fmt.Sprint(i), func(t *testing.T) {
    41  			in := lib.ParseInput(test.input, parse)
    42  			require.Equal(t, test.expect, part1(in))
    43  		})
    44  	}
    45  }
    46  
    47  func TestPart2(t *testing.T) {
    48  	type test struct {
    49  		input  string
    50  		expect int
    51  	}
    52  
    53  	tests := []test{
    54  		test{
    55  			input: `shiny gold bags contain 2 dark red bags.
    56  dark red bags contain 2 dark orange bags.
    57  dark orange bags contain 2 dark yellow bags.
    58  dark yellow bags contain 2 dark green bags.
    59  dark green bags contain 2 dark blue bags.
    60  dark blue bags contain 2 dark violet bags.
    61  dark violet bags contain no other bags.`,
    62  			expect: 126,
    63  		},
    64  	}
    65  
    66  	for i, test := range tests {
    67  		t.Run(fmt.Sprint(i), func(t *testing.T) {
    68  			in := lib.ParseInput(test.input, parse)
    69  			require.Equal(t, test.expect, part2(in))
    70  		})
    71  	}
    72  }