Files
MujicaUI/greeks_table_test.go
T

55 lines
1.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package mujica
import (
"math"
"testing"
"github.com/egoist/mygo/ui"
)
func greeksRows() []GreeksRow {
return []GreeksRow{
{Label: "AAPL 230 C", Greeks: OptionGreeks{0.52, 0.031, -0.12, 0.21, 0.05}},
{Label: "AAPL 220 P", Greeks: OptionGreeks{-0.38, 0.028, -0.10, 0.19, math.NaN()}},
}
}
func TestGreeksTableValuesAndPrecision(t *testing.T) {
tt := chatTester(640, 320, func(c *ui.Context) { GreeksTable(c, greeksRows(), GreeksTableOptions{}) })
for _, s := range []string{"Delta", "Rho", "+0.5200", "−0.1200", "+0.0310", "—"} {
if !tt.HasText(s) {
t.Errorf("%q missing from %q", s, tt.Texts())
}
}
tt = chatTester(640, 320, func(c *ui.Context) { GreeksTable(c, greeksRows(), GreeksTableOptions{Decimals: 2}) })
if !tt.HasText("+0.52") || tt.HasText("+0.5200") {
t.Fatalf("decimals: %q", tt.Texts())
}
}
func TestGreeksTableNotes(t *testing.T) {
tt := chatTester(640, 320, func(c *ui.Context) { GreeksTable(c, greeksRows(), GreeksTableOptions{}) })
if tt.HasText("Price change per day as time passes.") {
t.Fatal("notes shown without Notes")
}
tt = chatTester(640, 420, func(c *ui.Context) { GreeksTable(c, greeksRows(), GreeksTableOptions{Notes: true}) })
if !tt.HasText("Price change per day as time passes.") {
t.Fatal("notes missing")
}
defer func() {
if recover() == nil {
t.Fatal("no panic")
}
}()
ui.Render(func(c *ui.Context) {
Use(c, Settings{})
GreeksTable(c, nil, GreeksTableOptions{Decimals: -1})
}, 100, 100, 1)
}
func TestGreeksTableSnapshot(t *testing.T) {
snapshot(t, "greeks_table", 640, 300, func(c *ui.Context) {
ui.Column(c).Padding(16).Children(func() { GreeksTable(c, greeksRows(), GreeksTableOptions{Notes: true}) })
})
}