Exemplo n.º 1
0
func TestTransposeToColumns(t *testing.T) {
	reader, e := dsv.NewReader("testdata/config_skip.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader.SetMaxRows(-1)

	_, e = dsv.Read(reader)

	if e != io.EOF {
		t.Fatal(e)
	}

	ds := reader.GetDataset().(tabula.DatasetInterface)
	ds.TransposeToColumns()

	exp := fmt.Sprint(expSkipColumnsAll)

	columns := ds.GetDataAsColumns()

	got := fmt.Sprint(*columns)

	assert(t, exp, got, true)

	e = reader.Close()
	if e != nil {
		t.Fatal(e)
	}
}
Exemplo n.º 2
0
/*
TestReaderSkip will test the 'Skip' option in Metadata.
*/
func TestReaderSkip(t *testing.T) {
	dsvReader, e := dsv.NewReader("testdata/config_skip.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	doRead(t, dsvReader, expSkip)

	e = dsvReader.Close()
	if e != nil {
		t.Fatal(e)
	}
}
Exemplo n.º 3
0
/*
TestReaderOpen real example from the start.
*/
func TestReaderOpen(t *testing.T) {
	dsvReader, e := dsv.NewReader("testdata/config.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	doRead(t, dsvReader, expectation)

	e = dsvReader.Close()
	if e != nil {
		t.Fatal(e)
	}
}
Exemplo n.º 4
0
func TestSplitRowsByValue(t *testing.T) {
	reader, e := dsv.NewReader("testdata/config.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader.SetMaxRows(256)

	_, e = dsv.Read(reader)

	if e != nil && e != io.EOF {
		t.Fatal(e)
	}

	ds := reader.GetDataset().(tabula.DatasetInterface)
	splitL, splitR, e := tabula.SplitRowsByValue(ds, 0, 6)

	if e != nil {
		t.Fatal(e)
	}

	// test left split
	exp := ""
	for x := 0; x < 4; x++ {
		exp += expectation[x]
	}

	got := fmt.Sprint(splitL.GetDataAsRows())

	assert(t, exp, got, true)

	// test right split
	exp = ""
	for x := 4; x < len(expectation); x++ {
		exp += expectation[x]
	}

	got = fmt.Sprint(splitR.GetDataAsRows())

	assert(t, exp, got, true)

	e = reader.Close()
	if e != nil {
		t.Fatal(e)
	}
}
Exemplo n.º 5
0
func TestSortColumnsByIndex(t *testing.T) {
	reader, e := dsv.NewReader("testdata/config_skip.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader.SetMaxRows(-1)

	_, e = dsv.Read(reader)
	if e != io.EOF {
		t.Fatal(e)
	}

	// reverse the data
	var idxReverse []int
	var expReverse []string

	for x := len(expSkip) - 1; x >= 0; x-- {
		idxReverse = append(idxReverse, x)
		expReverse = append(expReverse, expSkip[x])
	}

	ds := reader.GetDataset().(tabula.DatasetInterface)

	tabula.SortColumnsByIndex(ds, idxReverse)

	exp := strings.Join(expReverse, "")
	got := fmt.Sprint(ds.GetDataAsRows())

	assert(t, exp, got, true)

	exp = "[" + strings.Join(expSkipColumnsAllRev, " ") + "]"

	columns := ds.GetDataAsColumns()

	got = fmt.Sprint(*columns)

	assert(t, exp, got, true)

	e = reader.Close()
	if e != nil {
		t.Fatal(e)
	}
}
Exemplo n.º 6
0
func TestReaderWithClaset(t *testing.T) {
	fcfg := "testdata/claset.dsv"

	claset := tabula.Claset{}

	_, e := dsv.NewReader(fcfg, &claset)
	if e != nil {
		t.Fatal(e)
	}

	assert(t, 3, claset.GetClassIndex(), true)

	claset.SetMajorityClass("regular")
	claset.SetMinorityClass("vandalism")

	clone := claset.Clone().(tabula.ClasetInterface)

	assert(t, 3, clone.GetClassIndex(), true)
	assert(t, "regular", clone.MajorityClass(), true)
	assert(t, "vandalism", clone.MinorityClass(), true)
}
Exemplo n.º 7
0
func TestMergeRows(t *testing.T) {
	reader1, e := dsv.NewReader("testdata/config.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader2, e := dsv.NewReader("testdata/config_skip.dsv", nil)
	if nil != e {
		t.Fatal(e)
	}

	reader1.SetMaxRows(-1)
	reader2.SetMaxRows(-1)

	_, e = dsv.Read(reader1)
	if e != io.EOF {
		t.Fatal(e)
	}

	_, e = dsv.Read(reader2)
	if e != io.EOF {
		t.Fatal(e)
	}

	e = reader1.Close()
	if e != nil {
		t.Fatal(e)
	}

	e = reader2.Close()
	if e != nil {
		t.Fatal(e)
	}

	reader1.MergeRows(reader2)

	// write merged reader
	writer, e := dsv.NewWriter("")
	if e != nil {
		t.Fatal(e)
	}

	outfile := "testdata/output_merge_rows.dat"

	e = writer.OpenOutput(outfile)

	if e != nil {
		t.Fatal(e)
	}

	sep := "\t"
	ds1 := reader1.GetDataset().(tabula.DatasetInterface)
	_, e = writer.WriteRawDataset(ds1, &sep)

	if e != nil {
		t.Fatal(e)
	}

	e = writer.Close()
	if e != nil {
		t.Fatal(e)
	}

	expfile := "testdata/expected_merge_rows.dat"
	assertFile(t, outfile, expfile, true)
}