Skip to content

Instantly share code, notes, and snippets.

@ivoscc
Created July 14, 2013 07:37
Show Gist options
  • Save ivoscc/5993521 to your computer and use it in GitHub Desktop.
Save ivoscc/5993521 to your computer and use it in GitHub Desktop.
package memories
import (
"math/rand"
"time"
"testing"
)
func TestSRAM(t *testing.T) {
rand.Seed(time.Now().UnixNano())
random_size := rand.Intn(32) + 1
sram := &SRAM{random_size, make([]uint8, random_size)}
// Read empty SRAM and assert it's initialized to zero
for i := 0; i < random_size; i++ {
if value, err := sram.read(i); value != 0 || err != nil {
t.Errorf("SRAM not initialized to 0.")
}
}
// read and write to invalid addresses
value, err := sram.read(-1)
if value != 0 || err == nil {
t.Errorf("Constraints not applied")
}
err = sram.write(random_size + 1, 0x20)
if err == nil {
t.Errorf("Constraints not applied")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment