bitbucket.org/ai69/amoy@v0.2.3/render_test.go (about)

     1  package amoy
     2  
     3  import "testing"
     4  
     5  func TestRenderSparkline(t *testing.T) {
     6  	tests := []struct {
     7  		name string
     8  		nums []float64
     9  		want string
    10  	}{
    11  		{"Same", []float64{1, 1, 1, 1, 1}, `▁▁▁▁▁`},
    12  		{"Peak", []float64{1, 2, 3, 4, 5, 6, 7, 8, 7, 6, 5, 4, 3, 2, 1}, `▁▂▃▄▅▆▇█▇▆▅▄▃▂▁`},
    13  		{"Low and High", []float64{0, 1, 19.9, 20}, `▁▁▇█`},
    14  		{"Negative", []float64{-20, -10, 0, 10, 20}, `▁▂▄▆█`},
    15  		{"Normal", []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, `▁▁▂▃▄▄▅▆▇█`},
    16  		{"Large Numbers", []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 100, 200}, `▁▁▁▁▁▁▁▁▁▁▄█`},
    17  		{"Random Numbers", []float64{4, 2, 1, 6, 3, 9, 1, 4, 2, 15, 14, 9, 8, 6, 10, 13, 15, 12, 10, 5, 3, 6, 1}, `▂▁▁▃▂▅▁▂▁█▇▅▄▃▅▇█▆▅▃▂▃▁`},
    18  	}
    19  	for _, tt := range tests {
    20  		t.Run(tt.name, func(t *testing.T) {
    21  			if got := RenderSparkline(tt.nums); got != tt.want {
    22  				t.Errorf("RenderSparkline(%v) = %v, want %v", tt.nums, got, tt.want)
    23  			}
    24  		})
    25  	}
    26  }
    27  
    28  func TestRenderPartialBlock(t *testing.T) {
    29  	tests := []struct {
    30  		name   string
    31  		num    float64
    32  		length int
    33  		want   string
    34  	}{
    35  		{"Zero", 0, 1, `░`},
    36  		{"One", 1, 1, `█`},
    37  		{"Half", 0.5, 1, `▌`},
    38  		{"Quarter", 0.25, 1, `▎`},
    39  		{"Three Quarters", 0.75, 1, `▊`},
    40  		{"Eighth", 0.125, 1, `▏`},
    41  		{"Negative", -1, 1, `░`},
    42  		{"Large", 2, 1, `█`},
    43  		{"Length 2", 0.5, 2, `█░`},
    44  		{"Length 3", 0.5, 3, `█▌░`},
    45  		{"Length 4", 0.5, 4, `██░░`},
    46  		{"Length 4 More", 0.748, 4, `███░`},
    47  	}
    48  	for _, tt := range tests {
    49  		t.Run(tt.name, func(t *testing.T) {
    50  			if got := RenderPartialBlock(tt.num, tt.length); got != tt.want {
    51  				t.Errorf("RenderPartialBlock(%.2f, %d) = %v, want %v", tt.num, tt.length, got, tt.want)
    52  			}
    53  		})
    54  	}
    55  }