mdb/mapindex_ex_test.go

36 lines
751 B
Go

package mdb
/*Copyright (c) 2022, John David Lee
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
*/
import (
"fmt"
"reflect"
)
func (m *MapIndex[K, T]) Equals(rhs *MapIndex[K, T]) error {
return m.EqualsMap(rhs.m)
}
func (m *MapIndex[K, T]) EqualsMap(data map[K]*T) error {
if len(m.m) != len(data) {
return fmt.Errorf("Expected %d items, but found %d.", len(data), len(m.m))
}
for key, exp := range data {
val, ok := m.Get(key)
if !ok {
return fmt.Errorf("No value for %v. Expected: %v", key, *exp)
}
if !reflect.DeepEqual(val, *exp) {
return fmt.Errorf("Value mismatch %v: %v != %v", key, val, *exp)
}
}
return nil
}