github.com/kintar/etxt@v0.0.9/emask/bold_test.go (about)

     1  //go:build gtxt
     2  
     3  package emask
     4  
     5  import "testing"
     6  
     7  func TestFauxBoldWhole(t *testing.T) {
     8  	tests := []struct {
     9  		w   int
    10  		in  []uint8
    11  		out []uint8
    12  	}{
    13  		{w: 0, in: []uint8{0, 100, 0, 100, 0}, out: []uint8{0, 100, 0, 100, 0}},
    14  		{w: 1, in: []uint8{0, 100, 0, 100, 0}, out: []uint8{0, 100, 100, 100, 100}},
    15  		{w: 1, in: []uint8{0, 100, 50, 100, 0}, out: []uint8{0, 100, 100, 100, 100}},
    16  		{w: 1, in: []uint8{0, 9, 0, 0, 9, 0, 0}, out: []uint8{0, 9, 9, 0, 9, 9, 0}},
    17  		{w: 2, in: []uint8{5, 0, 0, 0, 5, 0, 0}, out: []uint8{5, 5, 5, 0, 5, 5, 5}},
    18  		{w: 2, in: []uint8{0, 5, 6, 4, 0, 0}, out: []uint8{0, 5, 6, 6, 6, 4}},
    19  		{w: 1, in: []uint8{9, 8, 7, 8, 9, 0}, out: []uint8{9, 9, 8, 8, 9, 9}},
    20  		{w: 1, in: []uint8{9, 1, 1, 2, 9, 0}, out: []uint8{9, 9, 1, 2, 9, 9}},
    21  		{w: 3, // real tests be like...
    22  			in:  []uint8{0, 0, 0, 0, 0, 200, 255, 235, 250, 230, 97, 2, 0, 0, 0, 0, 0, 78, 249, 255, 252, 111, 251, 251, 148, 19, 0, 0, 0, 0, 0, 28, 214, 255, 255, 120, 0, 0, 0, 0, 0},
    23  			out: []uint8{0, 0, 0, 0, 0, 200, 255, 255, 255, 255, 250, 250, 230, 97, 2, 0, 0, 78, 249, 255, 255, 255, 255, 252, 251, 251, 251, 148, 19, 0, 0, 28, 214, 255, 255, 255, 255, 255, 120, 0, 0},
    24  		},
    25  		{w: 8,
    26  			in:  []uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 250, 255, 255, 255, 152, 74, 47, 69, 102, 169, 240, 254, 170, 102, 245, 252, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    27  			out: []uint8{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254, 254, 254, 254, 254, 252, 252, 252, 252, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    28  		},
    29  	}
    30  
    31  	rast := FauxRasterizer{}
    32  	for i, test := range tests {
    33  		rast.SetExtraWidth(float64(test.w))
    34  		out := make([]uint8, len(test.in))
    35  		for n, value := range test.in {
    36  			out[n] = value
    37  		}
    38  		rast.applyRowExtraWidth(out, out, 0, 999)
    39  		if !eqSliceUint8(out, test.out) {
    40  			t.Fatalf("test#%d: in %v (+%d), expected %v, got %v", i, test.in, test.w, test.out, out)
    41  		}
    42  	}
    43  }
    44  
    45  func TestFauxBoldFract(t *testing.T) {
    46  	tests := []struct {
    47  		w   float64
    48  		in  []uint8
    49  		out []uint8
    50  	}{
    51  		{w: 0.5, in: []uint8{0, 100, 0, 100, 0}, out: []uint8{0, 100, 50, 100, 50}},
    52  		{w: 0.5, in: []uint8{0, 100, 50, 25, 0}, out: []uint8{0, 100, 75, 37, 12}},
    53  		{w: 0.5, in: []uint8{0, 100, 50, 100, 0}, out: []uint8{0, 100, 75, 100, 50}},
    54  		{w: 0.5, in: []uint8{0, 100, 0, 50, 0}, out: []uint8{0, 100, 50, 50, 25}},
    55  		{w: 0.125, in: []uint8{100, 0, 0, 100, 0}, out: []uint8{100, 12, 0, 100, 12}},
    56  		{w: 0.625, in: []uint8{100, 0, 0, 100, 0}, out: []uint8{100, 62, 0, 100, 62}},
    57  		{w: 1.5, in: []uint8{100, 0, 0, 100, 0, 0}, out: []uint8{100, 100, 50, 100, 100, 50}},
    58  		{w: 1.5, in: []uint8{0, 50, 0, 50, 0, 100, 0, 0}, out: []uint8{0, 50, 50, 50, 50, 100, 100, 50}},
    59  		{w: 8.5, in: []uint8{2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, out: []uint8{2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 0, 0}},
    60  	}
    61  
    62  	rast := FauxRasterizer{}
    63  	for i, test := range tests {
    64  		rast.SetExtraWidth(test.w)
    65  		out := make([]uint8, len(test.in))
    66  		for n, value := range test.in {
    67  			out[n] = value
    68  		}
    69  		rast.applyRowExtraWidth(out, out, 0, 999)
    70  		if !eqSliceUint8(out, test.out) {
    71  			t.Fatalf("test#%d: in %v (+%0.1f), expected %v, got %v", i, test.in, test.w, test.out, out)
    72  		}
    73  	}
    74  }
    75  
    76  func eqSliceUint8(a, b []uint8) bool {
    77  	if len(a) != len(b) {
    78  		return false
    79  	}
    80  	for i, valueA := range a {
    81  		if valueA != b[i] {
    82  			return false
    83  		}
    84  	}
    85  	return true
    86  }