refactor with sugar-n-spice
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/DonovanKelly/sugar-n-spice/set"
|
||||
"github.com/google/uuid"
|
||||
"go-nkode/config"
|
||||
"go-nkode/internal/models"
|
||||
@@ -38,8 +39,8 @@ func (c *Customer) IsValidNKode(kp KeypadDimension, passcodeAttrIdx []int) error
|
||||
if validIdx := kp.ValidateAttributeIndices(passcodeAttrIdx); !validIdx {
|
||||
return config.ErrInvalidNKodeIdx
|
||||
}
|
||||
passcodeSetVals := make(utils.Set[uint64])
|
||||
passcodeAttrVals := make(utils.Set[uint64])
|
||||
passcodeSetVals := make(set.Set[uint64])
|
||||
passcodeAttrVals := make(set.Set[uint64])
|
||||
attrVals, err := c.Attributes.AttrValsForKp(kp)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/DonovanKelly/sugar-n-spice/all"
|
||||
"go-nkode/config"
|
||||
py "go-nkode/internal/utils"
|
||||
)
|
||||
|
||||
type KeypadDimension struct {
|
||||
@@ -26,13 +26,13 @@ func (kp *KeypadDimension) IsValidKeypadDimension() error {
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) ValidKeySelections(selectedKeys []int) bool {
|
||||
return py.All[int](selectedKeys, func(idx int) bool {
|
||||
return all.All[int](selectedKeys, func(idx int) bool {
|
||||
return 0 <= idx && idx < kp.NumbOfKeys
|
||||
})
|
||||
}
|
||||
|
||||
func (kp *KeypadDimension) ValidateAttributeIndices(attrIndicies []int) bool {
|
||||
return py.All[int](attrIndicies, func(i int) bool {
|
||||
return all.All[int](attrIndicies, func(i int) bool {
|
||||
return i >= 0 && i < kp.TotalAttrs()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/DonovanKelly/sugar-n-spice/set"
|
||||
"go-nkode/config"
|
||||
"go-nkode/internal/models"
|
||||
"go-nkode/internal/security"
|
||||
"go-nkode/internal/utils"
|
||||
"log"
|
||||
)
|
||||
|
||||
@@ -122,15 +122,15 @@ func (u *UserInterface) randomAttributeRotation() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *UserInterface) AttributeAdjacencyGraph() (map[int]utils.Set[int], error) {
|
||||
func (u *UserInterface) AttributeAdjacencyGraph() (map[int]set.Set[int], error) {
|
||||
interfaceKeypad, err := u.InterfaceMatrix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
graph := make(map[int]utils.Set[int])
|
||||
graph := make(map[int]set.Set[int])
|
||||
|
||||
for _, key := range interfaceKeypad {
|
||||
keySet := utils.NewSetFromSlice(key)
|
||||
keySet := set.NewSetFromSlice(key)
|
||||
for _, attr := range key {
|
||||
attrAdjacency := keySet.Copy()
|
||||
attrAdjacency.Remove(attr)
|
||||
@@ -154,7 +154,7 @@ func (u *UserInterface) LoginShuffle() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
selectedSets := utils.NewSetFromSlice[int](setIdxs[:numbOfSelectedSets])
|
||||
selectedSets := set.NewSetFromSlice[int](setIdxs[:numbOfSelectedSets])
|
||||
|
||||
for keyIdx, key := range keypadSet1 {
|
||||
for idx := range key {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/DonovanKelly/sugar-n-spice/all"
|
||||
"github.com/DonovanKelly/sugar-n-spice/set"
|
||||
"github.com/google/uuid"
|
||||
"go-nkode/config"
|
||||
"go-nkode/internal/models"
|
||||
"go-nkode/internal/security"
|
||||
py "go-nkode/internal/utils"
|
||||
"log"
|
||||
"sort"
|
||||
)
|
||||
@@ -50,7 +51,7 @@ func NewSignupResetSession(userEmail models.UserEmail, kp KeypadDimension, custo
|
||||
}
|
||||
|
||||
func (s *UserSignSession) DeducePasscode(confirmKeyEntry models.KeySelection) ([]int, error) {
|
||||
validEntry := py.All[int](confirmKeyEntry, func(i int) bool {
|
||||
validEntry := all.All[int](confirmKeyEntry, func(i int) bool {
|
||||
return 0 <= i && i < s.Kp.NumbOfKeys
|
||||
})
|
||||
|
||||
@@ -93,8 +94,8 @@ func (s *UserSignSession) DeducePasscode(confirmKeyEntry models.KeySelection) ([
|
||||
passcode := make([]int, passcodeLen)
|
||||
|
||||
for idx := 0; idx < passcodeLen; idx++ {
|
||||
setKey := py.NewSetFromSlice[int](setKeyVals[idx])
|
||||
confirmKey := py.NewSetFromSlice[int](confirmKeyVals[idx])
|
||||
setKey := set.NewSetFromSlice[int](setKeyVals[idx])
|
||||
confirmKey := set.NewSetFromSlice[int](confirmKeyVals[idx])
|
||||
intersection := setKey.Intersect(confirmKey)
|
||||
if intersection.Size() < 1 {
|
||||
log.Printf("set and confirm do not intersect at index %d", idx)
|
||||
@@ -111,7 +112,7 @@ func (s *UserSignSession) DeducePasscode(confirmKeyEntry models.KeySelection) ([
|
||||
}
|
||||
|
||||
func (s *UserSignSession) SetUserNKode(keySelection models.KeySelection) (models.IdxInterface, error) {
|
||||
validKeySelection := py.All[int](keySelection, func(i int) bool {
|
||||
validKeySelection := all.All[int](keySelection, func(i int) bool {
|
||||
return 0 <= i && i < s.Kp.NumbOfKeys
|
||||
})
|
||||
if !validKeySelection {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package entities
|
||||
|
||||
import (
|
||||
"github.com/DonovanKelly/sugar-n-spice/all"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go-nkode/internal/models"
|
||||
py "go-nkode/internal/utils"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -120,12 +120,12 @@ func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
|
||||
shuffleCompare[idx] = val == postShuffle[idx]
|
||||
}
|
||||
|
||||
allTrue := py.All[bool](shuffleCompare, func(n bool) bool {
|
||||
allTrue := all.All[bool](shuffleCompare, func(n bool) bool {
|
||||
return n == true
|
||||
})
|
||||
assert.False(t, allTrue)
|
||||
|
||||
allFalse := py.All[bool](shuffleCompare, func(n bool) bool {
|
||||
allFalse := all.All[bool](shuffleCompare, func(n bool) bool {
|
||||
return n == false
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user