|
| 1 | +package types |
| 2 | + |
| 3 | +/*****************************************************************************\ |
| 4 | + * Copyright 2024 Lawrence Livermore National Security, LLC |
| 5 | + * (c.f. AUTHORS, NOTICE.LLNS, LICENSE) |
| 6 | + * |
| 7 | + * This file is part of the Flux resource manager framework. |
| 8 | + * For details, see https://github.com/flux-framework. |
| 9 | + * |
| 10 | + * SPDX-License-Identifier: LGPL-3.0 |
| 11 | +\*****************************************************************************/ |
| 12 | + |
| 13 | +import ( |
| 14 | + "testing" |
| 15 | +) |
| 16 | + |
| 17 | +// List of match types, purposefully out of order |
| 18 | +var matchTypes = []MatchType{ |
| 19 | + MatchAllocateWithSatisfiability, |
| 20 | + MatchAllocateOrElseReserve, |
| 21 | + MatchAllocate, |
| 22 | + MatchSatisfiability, |
| 23 | + MatchUnknown, |
| 24 | +} |
| 25 | + |
| 26 | +func TestToString(t *testing.T) { |
| 27 | + type test struct { |
| 28 | + description string |
| 29 | + input MatchType |
| 30 | + expected string |
| 31 | + } |
| 32 | + |
| 33 | + tests := []test{ |
| 34 | + {description: "unknown", input: MatchUnknown, expected: "unknown"}, |
| 35 | + {description: "allocate", input: MatchAllocate, expected: "allocate"}, |
| 36 | + {description: "satisfiability", input: MatchSatisfiability, expected: "satisfiability"}, |
| 37 | + {description: "allocate or else reserve", input: MatchAllocateOrElseReserve, expected: "allocate or else reserve"}, |
| 38 | + {description: "allocate with satisfiability", input: MatchAllocateWithSatisfiability, expected: "allocate with satisfiability"}, |
| 39 | + } |
| 40 | + for _, item := range tests { |
| 41 | + t.Run(item.description, func(t *testing.T) { |
| 42 | + value := item.input.String() |
| 43 | + t.Logf("got %s, want %s", value, item.expected) |
| 44 | + if item.expected != value { |
| 45 | + t.Errorf("got %s, want %s", value, item.expected) |
| 46 | + } |
| 47 | + }) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func TestAsInt(t *testing.T) { |
| 52 | + type test struct { |
| 53 | + description string |
| 54 | + input MatchType |
| 55 | + expected int |
| 56 | + } |
| 57 | + |
| 58 | + tests := []test{ |
| 59 | + {description: "unknown", input: MatchUnknown, expected: 0}, |
| 60 | + {description: "allocate", input: MatchAllocate, expected: 1}, |
| 61 | + {description: "satisfiability", input: MatchSatisfiability, expected: 4}, |
| 62 | + {description: "allocate or else reserve", input: MatchAllocateOrElseReserve, expected: 2}, |
| 63 | + {description: "allocate with satisfiability", input: MatchAllocateWithSatisfiability, expected: 3}, |
| 64 | + } |
| 65 | + for _, item := range tests { |
| 66 | + t.Run(item.description, func(t *testing.T) { |
| 67 | + value := int(item.input) |
| 68 | + t.Logf("got %d, want %d", value, item.expected) |
| 69 | + if item.expected != value { |
| 70 | + t.Errorf("got %d, want %d", value, item.expected) |
| 71 | + } |
| 72 | + }) |
| 73 | + } |
| 74 | +} |
0 commit comments