INNER CODE UNIT · Go

TestChain_UnmarshalJSON

mb-14/gomarkov · gomarkov_test.go:41

func TestChain_UnmarshalJSON(t *testing.T) {
	tests := []struct {
		name    string
		args    []byte
		wantErr bool
	}{
		{"Empty chain", []byte(`{"int":2,"spool_map":{},"freq_mat":{}}`), false},
		{"More complex chain", []byte(`{"int":1,"spool_map":{"^":0,"$":3,"data":2,"node":4,"test":1},"freq_mat":{"0":{"1":3},"1":{"2":2,"4":1},"2":{"3":2},"4":{"3":1}}}`), false},
		{"Invalid json", []byte(`{{"int":2,"spool_map":{},"freq_mat":{}}`), true},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			chain := NewChain(1)

			if err := chain.UnmarshalJSON(tt.args); (err != nil) != tt.wantErr {
				t.Errorf("Chain.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
			}
		})

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…