Skip to content

Commit

Permalink
brain/braintest: add test for forgetfulness
Browse files Browse the repository at this point in the history
Updates #41.
  • Loading branch information
zephyrtronium committed Feb 29, 2024
1 parent d0ebb35 commit f8d3912
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions brain/braintest/braintest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,44 @@ type Interface interface {
//
// If a brain cannot be created without error, new should call t.Fatal.
func Test(ctx context.Context, t *testing.T, new func(context.Context) Interface) {
t.Run("forgetful", testForgetful(ctx, new(ctx)))
t.Run("combinatoric", testCombinatoric(ctx, new(ctx)))
}

// testForgetful tests that a brain forgets what it forgets.
func testForgetful(ctx context.Context, br Interface) func(t *testing.T) {
return func(t *testing.T) {
id := uuid.UUID{1}
tag := "bocchi"
msg := brain.MessageMeta{
ID: id,
User: userhash.Hash{2},
Tag: tag,
Time: time.Unix(0, 0),
}
text := "bocchi ryou nijika kita"
if err := brain.Learn(ctx, br, &msg, brain.Tokens(nil, text)); err != nil {
t.Errorf("failed to learn: %v", err)
}
s, err := brain.Speak(ctx, br, tag, "")
if err != nil {
t.Errorf("failed to speak: %v", err)
}
if s != text {
t.Errorf("surprise thought: %q", s)
}
if err := brain.Forget(ctx, br, tag, brain.Tokens(nil, text)); err != nil {
t.Errorf("failed to forget: %v", err)
}
// We don't really care about an error here, since the brain is empty.
// All we care about is no thoughts.
s, _ = brain.Speak(ctx, br, tag, "")
if s != "" {
t.Errorf("remembered that which must be forgotten: %v", err)
}
}
}

// testCombinatoric tests that chains can generate even with substantial
// overlap in learned material.
func testCombinatoric(ctx context.Context, br Interface) func(t *testing.T) {
Expand Down

0 comments on commit f8d3912

Please sign in to comment.