mirror of
https://github.com/wneessen/apg-go.git
synced 2024-11-09 15:52:54 +01:00
#53 Add tests and refactor Algorithm constants
Test suite `TestIntToAlgo` was added to `algo_test.go` to validate `IntToAlgo` function. Additionally, Algorithm constants in `algo.go` have been prefixed with "Algo". These changes were made in order to make the code clearer and ensure the function returns the expected values for the given inputs.
This commit is contained in:
parent
3cccc65498
commit
69bb1e4cb7
2 changed files with 32 additions and 9 deletions
18
algo.go
18
algo.go
|
@ -5,14 +5,14 @@ package apg
|
|||
type Algorithm int
|
||||
|
||||
const (
|
||||
// Pronouncable represents the algorithm for pronouncable passwords
|
||||
// AlgoPronouncable represents the algorithm for pronouncable passwords
|
||||
// (koremutake syllables)
|
||||
Pronouncable Algorithm = iota
|
||||
// Random represents the algorithm for purely random passwords according
|
||||
AlgoPronouncable Algorithm = iota
|
||||
// AlgoRandom represents the algorithm for purely random passwords according
|
||||
// to the provided password modes/flags
|
||||
Random
|
||||
// Unsupported represents an unsupported algorithm
|
||||
Unsupported
|
||||
AlgoRandom
|
||||
// AlgoUnsupported represents an unsupported algorithm
|
||||
AlgoUnsupported
|
||||
)
|
||||
|
||||
// IntToAlgo takes an int value as input and returns the corresponding
|
||||
|
@ -20,10 +20,10 @@ const (
|
|||
func IntToAlgo(a int) Algorithm {
|
||||
switch a {
|
||||
case 0:
|
||||
return Pronouncable
|
||||
return AlgoPronouncable
|
||||
case 1:
|
||||
return Random
|
||||
return AlgoRandom
|
||||
default:
|
||||
return Unsupported
|
||||
return AlgoUnsupported
|
||||
}
|
||||
}
|
||||
|
|
23
algo_test.go
Normal file
23
algo_test.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package apg
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestIntToAlgo(t *testing.T) {
|
||||
tt := []struct {
|
||||
name string
|
||||
a int
|
||||
e Algorithm
|
||||
}{
|
||||
{"AlgoPronouncable", 0, AlgoPronouncable},
|
||||
{"AlgoRandom", 1, AlgoRandom},
|
||||
{"AlgoUnsupported", 2, AlgoUnsupported},
|
||||
}
|
||||
for _, tc := range tt {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
a := IntToAlgo(tc.a)
|
||||
if a != tc.e {
|
||||
t.Errorf("IntToAlgo() failed, expected: %d, got: %d", tc.e, a)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue