-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I finally redid the file tests. Files were taking in a deck before, but now they don't and they return lists. This is a much better approach, because the deck object has a lot of extra information. This commit builds, but doesn't run. There is a problem with the deck filter logic. I need to add tests for that next and fix the problem.
- Loading branch information
Showing
9 changed files
with
98 additions
and
142 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,33 @@ | ||
package file | ||
|
||
import "testing" | ||
import "strings" | ||
import "github.com/alanxoc3/concards/core" | ||
|
||
const f1 = "@> hello there | i'm a beard <@" | ||
const c1 = "c435597dd9718c64b135087e944fd614 2020-01-01T00:00:00Z 3 sm2 2.5" | ||
|
||
const f2 = " @> hi | hello @> yoyo man go <@" | ||
const c2 = "19d480d8751e75494e70e65c18cc7fac 2020-01-11T00:00:00Z 2 sm2 .00001" | ||
|
||
const c3 = `19d480d8751e75494e70e65c18cc7fac 2020-01-01T00:00:00Z 2 sm2 .00001 | ||
c435597dd9718c64b135087e944fd614 2020-01-11T00:00:00Z 3 sm2 .05 | ||
b718c81a83d82bb83f82b0a8b18bb82b 2020-01-11T00:00:00Z 27 sm2 .05 | ||
` | ||
|
||
func TestReadMetasToDeck(t *testing.T) { | ||
d := core.NewDeck() | ||
ReadCardsToDeckHelper(strings.NewReader(f1+f2), d, "") | ||
ReadMetasToDeckHelper(strings.NewReader(c1), d) | ||
|
||
for i := 0; i < d.Len(); i++ { | ||
_, c, m := d.Get(i) | ||
switch i { | ||
case 0: | ||
if c.GetFactRaw(0) != "hello there" { | ||
t.Fail() | ||
} | ||
if m.NextStr() != "2020-01-01T00:00:00Z" { | ||
t.Fail() | ||
} | ||
if m.Streak != 3 { | ||
t.Fail() | ||
} | ||
case 1: | ||
} | ||
} | ||
} | ||
|
||
func TestReadCardsToDeck(t *testing.T) { | ||
d := core.NewDeck() | ||
ReadCardsToDeckHelper(strings.NewReader(f2), d, "nihao") | ||
|
||
for i := 0; i < d.Len(); i++ { | ||
_, c, _ := d.Get(i) | ||
switch i { | ||
case 0: | ||
if c.GetFactRaw(0) != "hi" { | ||
t.Fail() | ||
} | ||
if c.GetFile() != "nihao" { | ||
t.Fail() | ||
} | ||
case 1: | ||
if c.GetFactRaw(0) != "yoyo man go" { | ||
t.Fail() | ||
} | ||
} | ||
} | ||
} | ||
|
||
func TestWriteMetasToString(t *testing.T) { | ||
d := core.NewDeck() | ||
ReadMetasToDeckHelper(strings.NewReader(c3), d) | ||
str := WriteMetasToString(d) | ||
a := strings.Split(str, "\n") | ||
b := strings.Split(c3, "\n") | ||
|
||
if a[0] != b[0] { | ||
t.Fail() | ||
} | ||
if a[1] != b[2] { | ||
t.Fail() | ||
} | ||
if a[2] != b[1] { | ||
t.Fail() | ||
} | ||
package file_test | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/alanxoc3/concards/internal/card" | ||
"github.com/alanxoc3/concards/internal/file" | ||
"github.com/alanxoc3/concards/internal/meta" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestReadCards(t *testing.T) { | ||
fstr := " hello ye as \n @> hi | hello <@ asoe @> yoyo man go <@" | ||
cards := file.ReadCardsFromReader(strings.NewReader(fstr), "file") | ||
hi, _ := card.NewCards("file", "hi | hello") | ||
yo, _ := card.NewCards("file", "yoyo man go") | ||
|
||
assert.Equal(t, hi[0], cards[0]) | ||
assert.Equal(t, yo[0], cards[1]) | ||
} | ||
|
||
/* | ||
// This is a manual test. | ||
func TestFile(t *testing.T) { | ||
d := core.NewDeck() | ||
ReadCardsToDeck(d, "../") | ||
func TestReadPredicts(t *testing.T) { | ||
fstr := `a 2020-02-01T00:00:00Z 2020-01-01T00:00:00Z 1 2 0 sm2 | ||
b 2020-02-01T00:00:00Z 2020-01-01T00:00:00Z 2 1 0 sm2 | ||
c 2020-02-01T00:00:00Z 2020-01-01T00:00:00Z 3 3 3 sm2` | ||
|
||
for i := 0; i < d.Len(); i++ { | ||
_, c, _ := d.Get(i) | ||
println(c.String()) | ||
} | ||
predicts := file.ReadPredictsFromReader(strings.NewReader(fstr)) | ||
assert.Len(t, predicts, 3) | ||
assert.Equal(t, predicts[0], meta.NewPredictFromStrings("a", "2020-02-01T00:00:00Z", "2020-01-01T00:00:00Z", "1", "2", "0", "sm2")) | ||
assert.Equal(t, predicts[1], meta.NewPredictFromStrings("b", "2020-02-01T00:00:00Z", "2020-01-01T00:00:00Z", "2", "1", "0", "sm2")) | ||
assert.Equal(t, predicts[2], meta.NewPredictFromStrings("c", "2020-02-01T00:00:00Z", "2020-01-01T00:00:00Z", "3", "3", "3", "sm2")) | ||
} | ||
*/ |
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
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
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
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