From 579f3c771bcebed3e9b145c1cb0f7d7054a94e37 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 20 Dec 2016 22:40:09 +0100 Subject: Subtests --- flood_test.go | 95 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 48 deletions(-) (limited to 'flood_test.go') diff --git a/flood_test.go b/flood_test.go index 952b35f..6e7e846 100644 --- a/flood_test.go +++ b/flood_test.go @@ -2,54 +2,53 @@ package main import "testing" -type floodTest struct { - Input string - Result bool -} - -var floodTestData = []floodTest{ - { - Input: `! ! ! ! ! ! ! !`, - Result: true, - }, - { - Input: `test test test test abc abc`, - Result: true, - }, - { - Input: `! test ! test ! test ! test !`, - Result: true, - }, - { - Input: `a b c d e f g h i j`, - Result: false, - }, - { - Input: `const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } };`, - Result: false, - }, - { - Input: `a = b > 3 ? 2 : 4`, - Result: false, - }, - { - Input: `AAAAAAAAAAAAAAAAAAAA`, - Result: true, - }, - { - Input: `AAAAAAAAAABBBBBBBBBB`, - Result: true, - }, - { - Input: `ivy 3 3 rho (iota 9) in 2 6 7 8 9`, - Result: false, - }, -} - func TestFlood(t *testing.T) { - for _, test := range floodTestData { - if isFlood(test.Input) != test.Result { - t.Error(test.Input, "expected", test.Result) - } + testCases := []struct { + Input string + Result bool + }{ + { + Input: `! ! ! ! ! ! ! !`, + Result: true, + }, + { + Input: `test test test test abc abc`, + Result: true, + }, + { + Input: `! test ! test ! test ! test !`, + Result: true, + }, + { + Input: `a b c d e f g h i j`, + Result: false, + }, + { + Input: `const union __infinity_un __infinity = { { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f } };`, + Result: false, + }, + { + Input: `a = b > 3 ? 2 : 4`, + Result: false, + }, + { + Input: `AAAAAAAAAAAAAAAAAAAA`, + Result: true, + }, + { + Input: `AAAAAAAAAABBBBBBBBBB`, + Result: true, + }, + { + Input: `ivy 3 3 rho (iota 9) in 2 6 7 8 9`, + Result: false, + }, + } + for _, tc := range testCases { + t.Run(tc.Input, func(t *testing.T) { + if isFlood(tc.Input) != tc.Result { + t.Errorf("want %v", tc.Result) + } + }) } } -- cgit v1.2.3