Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnferchermeli committed Mar 28, 2020
1 parent 523d881 commit 09ed3db
Showing 1 changed file with 83 additions and 38 deletions.
121 changes: 83 additions & 38 deletions internal/math_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ func TestMath_GetRectCenterColProperties(t *testing.T) {
assertResult func(t *testing.T, x, y, w, h float64)
}{
{
"When Image has width greater than height",
300,
200,
"When cel proportion is greater than col",
20,
26,
100.0,
func() *mocks.Pdf {
pdf := &mocks.Pdf{}
Expand All @@ -40,16 +40,36 @@ func TestMath_GetRectCenterColProperties(t *testing.T) {
pdf.AssertNumberOfCalls(t, "GetMargins", 1)
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 14.0, 0.1)
assert.InDelta(t, y, 21.8, 0.1)
assert.InDelta(t, w, 5.0, 0.1)
assert.InDelta(t, h, 3.3, 0.1)
assert.InDelta(t, x, 14.3, 0.1)
assert.InDelta(t, y, 11.0, 0.1)
assert.InDelta(t, w, 19.2, 0.1)
assert.InDelta(t, h, 25.0, 0.1)
},
},
{
"When cel proportion is greater than col, 45 percent",
20,
26,
45.0,
func() *mocks.Pdf {
pdf := &mocks.Pdf{}
pdf.On("GetMargins").Return(12.0, 11.0, 13.0, 15.0)
return pdf
},
func(t *testing.T, pdf *mocks.Pdf) {
pdf.AssertNumberOfCalls(t, "GetMargins", 1)
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 19.6, 0.1)
assert.InDelta(t, y, 17.8, 0.1)
assert.InDelta(t, w, 8.6, 0.1)
assert.InDelta(t, h, 11.2, 0.1)
},
},
{
"When Image has height greater than width",
200,
300,
"When cen proportion is less than col",
26,
20,
100.0,
func() *mocks.Pdf {
pdf := &mocks.Pdf{}
Expand All @@ -61,15 +81,15 @@ func TestMath_GetRectCenterColProperties(t *testing.T) {
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 17.0, 0.1)
assert.InDelta(t, y, 20.7, 0.1)
assert.InDelta(t, w, 5.0, 0.1)
assert.InDelta(t, h, 7.5, 0.1)
assert.InDelta(t, y, 16.8, 0.1)
assert.InDelta(t, w, 20.0, 0.1)
assert.InDelta(t, h, 15.3, 0.1)
},
},
{
"When Image has height greater than width, percent 45",
200,
300,
"When cen proportion is less than col, 45 percent",
26,
20,
45.0,
func() *mocks.Pdf {
pdf := &mocks.Pdf{}
Expand All @@ -80,10 +100,10 @@ func TestMath_GetRectCenterColProperties(t *testing.T) {
pdf.AssertNumberOfCalls(t, "GetMargins", 1)
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 18.3, 0.1)
assert.InDelta(t, y, 22.8, 0.1)
assert.InDelta(t, w, 2.2, 0.1)
assert.InDelta(t, h, 3.3, 0.1)
assert.InDelta(t, x, 22.5, 0.1)
assert.InDelta(t, y, 21.0, 0.1)
assert.InDelta(t, w, 9.0, 0.1)
assert.InDelta(t, h, 6.9, 0.1)
},
},
}
Expand All @@ -95,7 +115,7 @@ func TestMath_GetRectCenterColProperties(t *testing.T) {
math := internal.NewMath(pdf)

// Act
x, y, w, h := math.GetRectCenterColProperties(c.width, c.height, 5, 25.0, 2, c.percent)
x, y, w, h := math.GetRectCenterColProperties(c.width, c.height, 20, 25.0, 2, c.percent)

// Assert
c.assertPdfCalls(t, pdf)
Expand All @@ -114,9 +134,9 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) {
assertResult func(t *testing.T, x, y, w, h float64)
}{
{
"When Image has width greater than height",
300,
200,
"When cel proportion is greater than rectangle",
20,
26,
props.Rect{
Percent: 100,
Center: false,
Expand All @@ -134,13 +154,38 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) {
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 14.0, 0.1)
assert.InDelta(t, y, 11, 0.1)
assert.InDelta(t, w, 5, 0.1)
assert.InDelta(t, h, 3.3, 0.1)
assert.InDelta(t, w, 19.2, 0.1)
assert.InDelta(t, h, 25.0, 0.1)
},
},
{
"When cel proportion is greater than rectangle, 45 percent",
20,
26,
props.Rect{
Percent: 45,
Center: false,
Left: 0,
Top: 0,
},
func() *mocks.Pdf {
pdf := &mocks.Pdf{}
pdf.On("GetMargins").Return(12.0, 11.0, 13.0, 15.0)
return pdf
},
func(t *testing.T, pdf *mocks.Pdf) {
pdf.AssertNumberOfCalls(t, "GetMargins", 1)
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 14.0, 0.1)
assert.InDelta(t, y, 11, 0.1)
assert.InDelta(t, w, 8.6, 0.1)
assert.InDelta(t, h, 11.25, 0.1)
},
}, {
"When Image has height greater than width",
200,
300,
"When cel proportion is less than rectangle",
26,
20,
props.Rect{
Percent: 100,
Center: false,
Expand All @@ -158,14 +203,14 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) {
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 17.0, 0.1)
assert.InDelta(t, y, 12.0, 0.1)
assert.InDelta(t, w, 5.0, 0.1)
assert.InDelta(t, h, 7.5, 0.1)
assert.InDelta(t, w, 20.0, 0.1)
assert.InDelta(t, h, 15.3, 0.1)
},
},
{
"When Image has height greater than width, percent 45",
200,
300,
"When cel proportion is less than rectangle, 45 percent",
26,
20,
props.Rect{
Percent: 45,
Center: false,
Expand All @@ -182,9 +227,9 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) {
},
func(t *testing.T, x, y, w, h float64) {
assert.InDelta(t, x, 17.0, 0.1)
assert.InDelta(t, y, 12, 0.1)
assert.InDelta(t, w, 2.25, 0.1)
assert.InDelta(t, h, 3.3, 0.1)
assert.InDelta(t, y, 12.0, 0.1)
assert.InDelta(t, w, 9.0, 0.1)
assert.InDelta(t, h, 6.9, 0.1)
},
},
}
Expand All @@ -196,7 +241,7 @@ func TestMath_GetRectNonCenterColProperties(t *testing.T) {
math := internal.NewMath(pdf)

// Act
x, y, w, h := math.GetRectNonCenterColProperties(c.width, c.height, 5, 25.0, 2, c.prop)
x, y, w, h := math.GetRectNonCenterColProperties(c.width, c.height, 20.0, 25.0, 2, c.prop)

// Assert
c.assertPdfCalls(t, pdf)
Expand Down

0 comments on commit 09ed3db

Please sign in to comment.