ProDOS-Utilities/prodos/bitmap_test.go

85 lines
2.0 KiB
Go
Raw Normal View History

2021-06-09 12:23:18 +00:00
package prodos
import (
"fmt"
"testing"
)
func TestCreateVolumeBitmap(t *testing.T) {
var tests = []struct {
blocks int
want int
}{
{65536, 8192},
{65533, 8192},
{140, 512},
}
for _, tt := range tests {
testname := fmt.Sprintf("%d", tt.blocks)
t.Run(testname, func(t *testing.T) {
2021-06-29 02:26:20 +00:00
volumeBitMap := createVolumeBitmap(tt.blocks)
2021-06-09 12:23:18 +00:00
ans := len(volumeBitMap)
if ans != tt.want {
t.Errorf("got %d, want %d", ans, tt.want)
}
})
}
}
2021-06-26 01:15:20 +00:00
func TestCheckFreeBlockInVolumeBitmap(t *testing.T) {
var tests = []struct {
blocks int
want bool
}{
{0, false}, // boot block
{1, false}, // SOS boot block
{2, false}, // volume root
{21, false}, // end of volume bitmap
{22, true}, // beginning of free space
{8192, true}, // more free space
{65534, true}, // last free block
{65535, false}, // can't use last block because volume size is 0xFFFF, not 0x10000
}
for _, tt := range tests {
testname := fmt.Sprintf("%d", tt.blocks)
t.Run(testname, func(t *testing.T) {
2021-06-29 02:26:20 +00:00
volumeBitMap := createVolumeBitmap(65535)
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
2021-06-26 01:15:20 +00:00
if ans != tt.want {
t.Errorf("got %t, want %t", ans, tt.want)
}
})
}
}
func TestMarkBlockInVolumeBitmap(t *testing.T) {
var tests = []struct {
blocks int
want bool
}{
{0, false}, // boot block
{1, false}, // SOS boot block
{2, false}, // volume root
{21, false}, // end of volume bitmap
{22, true}, // beginning of free space
{999, false}, // end of volume bitmap
{8192, true}, // more free space
{65534, true}, // last free block
{65535, false}, // can't use last block because volume size is 0xFFFF, not 0x10000
}
for _, tt := range tests {
testname := fmt.Sprintf("%d", tt.blocks)
t.Run(testname, func(t *testing.T) {
volumeBitMap := createVolumeBitmap(65535)
markBlockInVolumeBitmap(volumeBitMap, 999)
ans := checkFreeBlockInVolumeBitmap(volumeBitMap, tt.blocks)
if ans != tt.want {
t.Errorf("got %t, want %t", ans, tt.want)
}
})
}
}