MCPcopy Create free account
hub / github.com/datasweet/datatable / TestRow

Function TestRow

table_test.go:157–188  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

155}
156
157func TestRow(t *testing.T) {
158 tb := datatable.New("test")
159 assert.NoError(t, tb.AddColumn("champ", datatable.String))
160 assert.NoError(t, tb.AddColumn("win", datatable.Int))
161 assert.NoError(t, tb.AddColumn("loose", datatable.Int, datatable.ColumnHidden(true)))
162 assert.NoError(t, tb.AddColumn("winRate", datatable.Float64, datatable.Expr("(`win` * 100 / (`win` + `loose`))")))
163 assert.Error(t, tb.AddColumn("winRate", datatable.String, datatable.Expr("test")))
164
165 assert.NoError(t, tb.AppendRow("Xerath", 25, 15, "expr"))
166 assert.NoError(t, tb.AppendRow("Malzahar", 16, 16, nil))
167 assert.NoError(t, tb.AppendRow("Vel'Koz", 7, 5, 3))
168
169 checkTable(t, tb,
170 "champ", "win", "winRate",
171 "Xerath", 25, 62.5,
172 "Malzahar", 16, 50.0,
173 "Vel'Koz", 7, 58.333333333333336,
174 )
175
176 r := tb.Row(0)
177 assert.Len(t, r, 3)
178 assert.Equal(t, r.Get("champ"), "Xerath")
179 assert.Equal(t, r.Get("win"), 25)
180 assert.Equal(t, r.Get("winRate"), 62.5)
181 assert.Nil(t, r.Get("loose"))
182 r = tb.Row(0, datatable.ExportHidden(true))
183 assert.Len(t, r, 4)
184 assert.Equal(t, r.Get("champ"), "Xerath")
185 assert.Equal(t, r.Get("win"), 25)
186 assert.Equal(t, r.Get("winRate"), 62.5)
187 assert.Equal(t, r.Get("loose"), 15)
188}

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
ColumnHiddenFunction · 0.92
ExprFunction · 0.92
ExportHiddenFunction · 0.92
checkTableFunction · 0.85
AddColumnMethod · 0.80
AppendRowMethod · 0.80
GetMethod · 0.65
RowMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected