Exercises/concept/lasagna/lasagna_test.go

OvenTime Should not be tested for OR it should not be an exported Const. Since the tests are in the same package there is no need to export and it would be best practice not to export this const from the package if it is not needed.

func TestOvenTime(t *testing.T) {
	tests := []lasagnaTests{
		{
			name:     "Calculates how many minutes the lasagna should be in the oven",
			layers:   0,
			time:     40,
			expected: 40,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := OvenTime; got != tt.expected {
				t.Errorf("OvenTime(%d)  = %d; want %d", tt.expected, got, tt.expected)
			}
		})
	}
}

How would you go about teaching people about, and testing, exported constants? Exporting constants is part of the lesson here.

I wouldn’t, it’s good to know how to export constants but writing a test for them is a bit excessive in my opinion. Especially since most students end up with a MagicNumber for the time for layer of 2 minutes anyways.

The “magic literal” point is a mentoring concern, and can come out in either review or the analyzer.

1 Like

Writing a test for them is how the exercise encourages/requires students to use what they learned. Exercism is built around the idea that practice is an important part of learning. If we want to teach students about exporting constants, we want to also have students practice using them, which means testing them.

Does that mean this is what the code would look like in production? Maybe not. But that’s not the goal – these exercises are often a bit contrived, with the goal of helping students practice and learn a concept.

1 Like