initial commits

master
Charles Iliya Krempeaux 2024-02-09 11:07:51 -08:00
parent 1d42f0eb32
commit 09b6eb0e7f
4 changed files with 100 additions and 0 deletions

3
maxint.go 100644
View File

@ -0,0 +1,3 @@
package imgrow
const intMax = int(^uint(0) >> 1)

3
minint.go 100644
View File

@ -0,0 +1,3 @@
package imgrow
const intMin = -intMax - 1

8
scalexy.go 100644
View File

@ -0,0 +1,8 @@
package imgrow
func scaleXY(scalar int, x int, y int) (int, int) {
x2 := x * scalar
y2 := y * scalar
return x2, y2
}

86
scalexy_test.go 100644
View File

@ -0,0 +1,86 @@
package imgrow
import (
"testing"
)
func TestScaleXY(t *testing.T) {
tests := []struct{
Scalar int
X int
Y int
ExpectedX int
ExpectedY int
}{
{
Scalar: -2,
X: 5,
Y: 7,
ExpectedX: -10,
ExpectedY: -14,
},
{
Scalar: -1,
X: 5,
Y: 7,
ExpectedX: -5,
ExpectedY: -7,
},
{
Scalar: 0,
X: 5,
Y: 7,
ExpectedX: 0,
ExpectedY: 0,
},
{
Scalar: 1,
X: 5,
Y: 7,
ExpectedX: 5,
ExpectedY: 7,
},
{
Scalar: 2,
X: 5,
Y: 7,
ExpectedX: 10,
ExpectedY: 14,
},
{
Scalar: 3,
X: 5,
Y: 7,
ExpectedX: 15,
ExpectedY: 21,
},
{
Scalar: 100,
X: -11,
Y: 13,
ExpectedX: -1100,
ExpectedY: 1300,
},
}
for testNumber, test := range tests {
actualX, actualY := scaleXY(test.Scalar, test.X, test.Y)
expectedX, expectedY := test.ExpectedX, test.ExpectedY
if expectedX != actualX || expectedY != actualY {
t.Errorf("For test #%d, the actual value is not what was expected.", testNumber)
t.Logf("EXPECTED (X,Y) = (%d, %d)", expectedX, expectedY)
t.Logf("ACTUAL (X,Y) = (%d, %d)", actualX, actualY)
t.Logf("SCALAR = %d", test.Scalar)
t.Logf("(X,Y) = (%d, %d)", test.X, test.Y)
continue
}
}
}