mirror of
https://github.com/emirpasic/gods.git
synced 2026-06-15 16:16:35 +03:00
- all stacks (de)serialization
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package arraystack
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -231,6 +232,34 @@ func TestStackIteratorLast(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStackSerialization(t *testing.T) {
|
||||
stack := New()
|
||||
stack.Push("a")
|
||||
stack.Push("b")
|
||||
stack.Push("c")
|
||||
|
||||
var err error
|
||||
assert := func() {
|
||||
if actualValue, expectedValue := fmt.Sprintf("%s%s%s", stack.Values()...), "cba"; actualValue != expectedValue {
|
||||
t.Errorf("Got %v expected %v", actualValue, expectedValue)
|
||||
}
|
||||
if actualValue, expectedValue := stack.Size(), 3; actualValue != expectedValue {
|
||||
t.Errorf("Got %v expected %v", actualValue, expectedValue)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("Got error %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
assert()
|
||||
|
||||
json, err := stack.ToJSON()
|
||||
assert()
|
||||
|
||||
err = stack.FromJSON(json)
|
||||
assert()
|
||||
}
|
||||
|
||||
func benchmarkPush(b *testing.B, stack *Stack, size int) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
for n := 0; n < size; n++ {
|
||||
|
||||
Reference in New Issue
Block a user