Skip to content

Commit

Permalink
GH-4 Updated the tests for multi sides.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanxoc3 committed Jun 27, 2020
1 parent f7988fa commit c0dc69b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
47 changes: 36 additions & 11 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import "fmt"
const fullSum = "c6cd355e32654cb4ba506b529ff32288971420ead2e36fdc69e802e9e7510315"
const halfSum = "c6cd355e32654cb4ba506b529ff32288"

var f1 = []string{ "hello", "there", "@", "i'm", "a", "beard", }
var f2 = []string{ "hello", }
var f3 = []string{ "i'm", "um", "@", "hello", }
var f4 = []string{ "alan", "the", "great", "@", "sy", "shoe", "yu", }
var f1 = "hello there @ i'm a beard"
var f2 = "hello"
var f3 = "i'm um @ hello"
var f4 = "alan the great @ sy shoe yu"
var f5 = "a @ b @ c @ d e @ f @ @ g"

func TestMeta(t *testing.T) {
a := NewMeta("2020-01-01T00:00:00Z", "0", "sm2", []string{"2.5"})
Expand All @@ -28,7 +29,7 @@ func TestParse(t *testing.T) {
}

func TestCard(t *testing.T) {
c, err := NewCard(f1, "")
c, err := NewCard("", f1)
if err != nil { t.FailNow() }

txt := c.String()
Expand All @@ -43,7 +44,7 @@ func TestCard(t *testing.T) {

func TestDeck(t *testing.T) {
d := NewDeck()
d.AddCardFromSides("afile", f1)
d.AddCardFromSides("afile", f1, false)
if d.GetCard(0).GetQuestion() != "hello there" { t.Fail() }
if !d.GetCard(0).HasAnswer() { t.Fail() }
if d.GetMeta(0) != nil { t.Fail() }
Expand All @@ -59,7 +60,7 @@ func TestDeck(t *testing.T) {
d.Forget(0)
if d.GetMeta(0) != nil { t.Fail() }
if !d.GetCard(0).HasAnswer() { t.Fail() }
d.AddCardFromSides("nofile", f1)
d.AddCardFromSides("nofile", f1, false)
if d.Len() != 1 { t.Fail() }
if d.GetCard(0).GetFile() != "afile" { t.Fail() }
d.FilterOutFile("nofile")
Expand All @@ -72,10 +73,10 @@ func TestDeck(t *testing.T) {

func TestDeckMove(t *testing.T) {
d := NewDeck()
d.AddCardFromSides("afile", f1)
d.AddCardFromSides("afile", f2)
d.AddCardFromSides("afile", f3)
d.AddCardFromSides("afile", f4)
d.AddCardFromSides("afile", f1, false)
d.AddCardFromSides("afile", f2, false)
d.AddCardFromSides("afile", f3, false)
d.AddCardFromSides("afile", f4, false)
d.TopToEnd()
if d.TopCard().GetQuestion() != "hello" { panic("Bad moves") }
if d.Len() != 4 { panic("Bad len") }
Expand All @@ -90,3 +91,27 @@ func TestDeckMove(t *testing.T) {
d.TopToEnd()
if d.TopCard().GetQuestion() != "hello there" { panic("Bad moves") }
}

func TestAddSubCards(t *testing.T) {
d := NewDeck()
d.AddCardFromSides("dat-file", f5, true)

if d.TopCard().GetQuestion() != "a" { panic("Subcards were inserted before the parent card.") }
if d.Len() != 6 { panic("Wrong number of sub cards inserted.") }
d.DelTop()
if d.TopCard().GetQuestion() != "b" { panic("Second card should be the first sub card.") }
if d.TopCard().GetFact(1) != "a" { panic("Answer isn't the parent card.") }
if d.Len() != 5 { panic("Delete didn't work.") }

if d.GetCard(1).GetQuestion() != "c" { panic("Sub cards not inserted in the correct order.") }
if d.GetCard(1).GetFact(1) != "a" { panic("Sub card doesn't have parent as the answer.") }

if d.GetCard(2).GetQuestion() != "d e" { panic("Sub cards not inserted in the correct order.") }
if d.GetCard(2).GetFact(1) != "a" { panic("Sub card doesn't have parent as the answer.") }

if d.GetCard(3).GetQuestion() != "f" { panic("Sub cards not inserted in the correct order.") }
if d.GetCard(3).GetFact(1) != "a" { panic("Sub card doesn't have parent as the answer.") }

if d.GetCard(4).GetQuestion() != "g" { panic("Sub cards not inserted in the correct order.") }
if d.GetCard(4).GetFact(1) != "a" { panic("Sub card doesn't have parent as the answer.") }
}
4 changes: 2 additions & 2 deletions file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ b718c81a83d82bb83f82b0a8b18bb82b 2020-01-11T00:00:00Z 27 sm2 .05

func TestReadMetasToDeck(t *testing.T) {
d := core.NewDeck()
ReadCardsToDeckHelper(strings.NewReader(f1 + f2), d, "")
ReadCardsToDeckHelper(strings.NewReader(f1 + f2), d, "", false)
ReadMetasToDeckHelper(strings.NewReader(c1), d)

for i := 0; i < d.Len(); i++ {
Expand All @@ -34,7 +34,7 @@ func TestReadMetasToDeck(t *testing.T) {

func TestReadCardsToDeck(t *testing.T) {
d := core.NewDeck()
ReadCardsToDeckHelper(strings.NewReader(f2), d, "nihao")
ReadCardsToDeckHelper(strings.NewReader(f2), d, "nihao", false)

for i := 0; i < d.Len(); i++ {
_, c, _ := d.Get(i)
Expand Down

0 comments on commit c0dc69b

Please sign in to comment.