A tool for archiving & converting scans of postcards, and information about them.
at main 56 lines 1.7 kB view raw
1package types_test 2 3import ( 4 "fmt" 5 "testing" 6 7 . "github.com/jphastings/dotpostcard/types" 8 "github.com/stretchr/testify/assert" 9) 10 11var transformCases = []struct { 12 onFront bool 13 flip Flip 14 transformed Point 15}{ 16 {true, FlipNone, Point{X: 0.13, Y: 0.17}}, 17 18 {true, FlipBook, Point{X: 0.13, Y: 0.085}}, 19 {false, FlipBook, Point{X: 0.13, Y: 0.585}}, 20 21 {true, FlipCalendar, Point{X: 0.13, Y: 0.085}}, 22 {false, FlipCalendar, Point{X: 0.13, Y: 0.585}}, 23 24 {true, FlipLeftHand, Point{X: 0.13, Y: 0.085}}, 25 {false, FlipLeftHand, Point{X: 0.17, Y: 0.935}}, 26 27 {true, FlipRightHand, Point{X: 0.13, Y: 0.085}}, 28 {false, FlipRightHand, Point{X: 0.83, Y: 0.565}}, 29} 30 31// Accuracy of floating point results 32const acc = 0.0000000001 33 34func TestTransformToDoubleSided(t *testing.T) { 35 original := Point{X: 0.13, Y: 0.17} 36 37 for _, c := range transformCases { 38 t.Run(fmt.Sprintf("Front:%v-Flip:%s", c.onFront, c.flip), func(t *testing.T) { 39 got := original.TransformToDoubleSided(c.onFront, c.flip) 40 assert.InDelta(t, c.transformed.X, got.X, acc, "Incorrect X value: wanted %v got %v", c.transformed.X, got.X) 41 assert.InDelta(t, c.transformed.Y, got.Y, acc, "Incorrect Y value: wanted %v got %v", c.transformed.X, got.Y) 42 }) 43 } 44} 45 46func TestTransformToSingleSided(t *testing.T) { 47 original := Point{X: 0.13, Y: 0.17} 48 49 for _, c := range transformCases { 50 t.Run(fmt.Sprintf("Front:%v-Flip:%s", c.onFront, c.flip), func(t *testing.T) { 51 got := c.transformed.TransformToSingleSided(c.onFront, c.flip) 52 assert.InDelta(t, original.X, got.X, acc, "Incorrect X value: wanted %v got %v", original.X, got.X) 53 assert.InDelta(t, original.Y, got.Y, acc, "Incorrect Y value: wanted %v got %v", original.X, got.Y) 54 }) 55 } 56}