Adding the challenge 0204

This commit is contained in:
2026-07-28 22:26:46 +02:00
parent ee49ef185b
commit df8c61b7b9
13 changed files with 704 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package db0204
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRowEncode(t *testing.T) {
schema := &Schema{
Table: "link",
Cols: []Column{
{Name: "time", Type: TypeI64},
{Name: "src", Type: TypeStr},
{Name: "dst", Type: TypeStr},
},
PKey: []int{1, 2}, // (src, dst)
}
row := Row{
Cell{Type: TypeI64, I64: 123},
Cell{Type: TypeStr, Str: []byte("a")},
Cell{Type: TypeStr, Str: []byte("b")},
}
key := []byte{'l', 'i', 'n', 'k', 0, 1, 0, 0, 0, 'a', 1, 0, 0, 0, 'b'}
val := []byte{123, 0, 0, 0, 0, 0, 0, 0}
assert.Equal(t, key, row.EncodeKey(schema))
assert.Equal(t, val, row.EncodeVal(schema))
decoded := schema.NewRow()
err := decoded.DecodeKey(schema, key)
assert.Nil(t, err)
err = decoded.DecodeVal(schema, val)
assert.Nil(t, err)
assert.Equal(t, row, decoded)
}
// QzBQWVJJOUhU https://trialofcode.org/