Created
July 14, 2013 07:37
-
-
Save ivoscc/5993521 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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