File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ func (s StateMap) SetState(stateType string, value bool) {
1313 s [stateType ] = value
1414}
1515
16+ // ToggleState toggles the value of the state with the provided key in the StateMap.
17+ func (s StateMap ) ToggleState (stateType string ) {
18+ s [stateType ] = ! s [stateType ]
19+ }
20+
1621// IsState return the value of the state provided from StateMap
1722func (s StateMap ) IsState (stateType string ) bool {
1823 if ok , v := s [stateType ]; ok {
Original file line number Diff line number Diff line change @@ -65,3 +65,37 @@ func TestStateMap_HasState(t *testing.T) {
6565 })
6666 }
6767}
68+
69+ func TestStateMap_ToggleState (t * testing.T ) {
70+ type args struct {
71+ stateType string
72+ }
73+ tests := []struct {
74+ name string
75+ args args
76+ want bool
77+ }{
78+ {
79+ name : "success - toggled the state in the state map" ,
80+ args : args {stateType : "key1" },
81+ want : false ,
82+ },
83+ {
84+ name : "success - toggled the state in the state map" ,
85+ args : args {stateType : "key2" },
86+ want : true ,
87+ }}
88+ for _ , tt := range tests {
89+ t .Run (tt .name , func (t * testing.T ) {
90+ state := NewStateMap ()
91+ state .SetState (tt .args .stateType , ! tt .want )
92+
93+ state .ToggleState (tt .args .stateType )
94+
95+ got := state .IsState (tt .args .stateType )
96+ if got != tt .want {
97+ t .Errorf ("ToggleState() : %v, want : %v" , got , tt .want )
98+ }
99+ })
100+ }
101+ }
You can’t perform that action at this time.
0 commit comments