Skip to content

Commit

Permalink
Fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sayden committed Nov 5, 2024
1 parent fbf1a9a commit 812f2d4
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 51 deletions.
51 changes: 25 additions & 26 deletions card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package counters

import (
"image/color"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -107,32 +106,32 @@ func TestApplyCardScaling(t *testing.T) {
t.Fatal(err)
}

f, _ := os.Create("/tmp/card_01.png")
defer f.Close()
err = template.Cards[0].EncodeImage(f, template)
if err != nil {
t.Fatal(err)
}

// assert.Equal(t, 120, template.Settings.Width)
// assert.Equal(t, 240, template.Settings.Height)
// assert.Equal(t, 120, template.Cards[0].Settings.Width)
// assert.Equal(t, 240, template.Cards[0].Settings.Height)
// assert.Equal(t, 120, template.Cards[0].Areas[0].Width)
// assert.Equal(t, 100, template.Cards[0].Areas[0].Height)
// assert.Equal(t, float64(2), *template.Settings.StrokeWidth)
// assert.Equal(t, 120, template.Cards[0].Images[0].Width)
// assert.Equal(t, 240, template.Cards[0].Images[0].Height)
// assert.Equal(t, 120, template.Cards[0].Texts[0].Settings.Width)
// assert.Equal(t, 240, template.Cards[0].Texts[0].Settings.Height)
// assert.Equal(t, float64(2), *template.Cards[0].Texts[0].Settings.StrokeWidth)

// canvas, err := template.Cards[0].ToCanvas(template)
// if !assert.NoError(t, err) {
// f, _ := os.Create("/tmp/card_01.png")
// defer f.Close()
// err = template.Cards[0].EncodeImage(f, template)
// if err != nil {
// t.Fatal(err)
// }
// if assert.NoError(t, err) {
// TestImageContent(t, "testdata/card_01.png", 5643, canvas)
// }

t.Skip("TODO: implement test")
assert.Equal(t, 120, template.Settings.Width)
assert.Equal(t, 240, template.Settings.Height)
assert.Equal(t, 120, template.Cards[0].Settings.Width)
assert.Equal(t, 240, template.Cards[0].Settings.Height)
assert.Equal(t, 120, template.Cards[0].Areas[0].Width)
assert.Equal(t, 100, template.Cards[0].Areas[0].Height)
assert.Equal(t, float64(2), *template.Settings.StrokeWidth)
assert.Equal(t, 120, template.Cards[0].Images[0].Width)
assert.Equal(t, 240, template.Cards[0].Images[0].Height)
assert.Equal(t, 120, template.Cards[0].Texts[0].Settings.Width)
assert.Equal(t, 240, template.Cards[0].Texts[0].Settings.Height)
assert.Equal(t, float64(2), *template.Cards[0].Texts[0].Settings.StrokeWidth)

canvas, err := template.Cards[0].ToCanvas(template)
if !assert.NoError(t, err) {
t.Fatal(err)
}
if assert.NoError(t, err) {
TestImageContent(t, "testdata/card_01.png", 5643, canvas)
}
}
1 change: 0 additions & 1 deletion cards_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func TestCardTemplate(t *testing.T) {
if assert.NoError(t, err) {
newTempl, err := ParseCardTemplate(byt)
if assert.NoError(t, err) {
// TODO
canvas, err := newTempl.Canvas(&newTempl.Settings, newTempl.Settings.Width, newTempl.Settings.Height)
if assert.NoError(t, err) {
assert.NotNil(t, canvas)
Expand Down
1 change: 0 additions & 1 deletion counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func (c *Counter) GetCounterFilename(sideName string, position int, filenamesInU
filenumber := 0
_, isFound := filenamesInUse.Load(res)
if isFound {
filenumber = 0
for {
tempRes := fmt.Sprintf("%s_%04d", res, filenumber)
_, isFound = filenamesInUse.Load(tempRes)
Expand Down
4 changes: 2 additions & 2 deletions counter_prototype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestJSONPrototypes(t *testing.T) {
// check the marshalling of the template to an expected byte slice
actualBytes, err := json.MarshalIndent(newTempl, "", " ")
assert.NoError(t, err)
if !assert.Equal(t, 17678, len(actualBytes)) {
if !assert.Equal(t, 18538, len(actualBytes)) {
t.FailNow()
}

Expand All @@ -74,7 +74,7 @@ func TestJSONPrototypes(t *testing.T) {
assert.NoError(t, err)

// // ensure we are using the expected file and that it has not been altered by mistake
if !assert.Equal(t, 17678, len(expectedBytes), "expected file has been altered, aborting test") {
if !assert.Equal(t, 18538, len(expectedBytes), "expected file has been altered, aborting test") {
t.FailNow()
}

Expand Down
2 changes: 1 addition & 1 deletion image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ func TestImageDraw(t *testing.T) {
err = testImage.Draw(testCanvas, 1)
assert.NoError(t, err)

TestImageContent(t, "testdata/image_draw_01.png", 13552, testCanvas)
TestImageContent(t, "testdata/image_draw_01.png", 13672, testCanvas)
})
}
4 changes: 2 additions & 2 deletions output/cards_to_png_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ func TestCardTemplate(t *testing.T) {
t.FailNow()
}
defer os.Remove(f.Name())
byt, err := os.ReadFile(fmt.Sprintf(template.OutputPath, 1))
gotBytes, err := os.ReadFile(fmt.Sprintf(template.OutputPath, 1))
if assert.NoError(t, err) {
expectedFile, err := os.Open("../testdata/card_template_01.png")
if assert.NoError(t, err) {
defer expectedFile.Close()

expectedBytes, err := io.ReadAll(expectedFile)
if assert.NoError(t, err) {
assert.Equal(t, expectedBytes, byt)
assert.Equal(t, expectedBytes, gotBytes)
}
}
}
Expand Down
Binary file modified testdata/card_template_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified testdata/image_draw_01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 48 additions & 18 deletions testdata/parse_template_01.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"columns": 7,
"mode": "template",
"output_folder": "../testdata/img",
"vassal": {},
"position_number_for_filename": 3,
"counters": [
{
"width": 82,
Expand All @@ -32,6 +34,7 @@
"stroke_width": -1,
"stroke_color": "black",
"image_scaling": "fitWidth",
"pretty_name": "both1_back",
"images": [
{
"width": 82,
Expand All @@ -50,7 +53,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"path": "../assets/binoculars.png",
"path": "../assets/stripe.png",
"scale": 0.5
}
],
Expand All @@ -73,7 +76,7 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 3,
"string": "both1"
"string": "both1b"
},
{
"width": 82,
Expand All @@ -93,9 +96,10 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 7,
"string": "1"
"string": "1b"
}
]
],
"filename": "both1_back.png"
},
{
"width": 82,
Expand All @@ -114,6 +118,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "both1",
"images": [
{
"width": 82,
Expand All @@ -132,7 +137,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"path": "../assets/stripe.png",
"path": "../assets/binoculars.png",
"scale": 0.5
}
],
Expand All @@ -155,7 +160,7 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 3,
"string": "both1b"
"string": "both1"
},
{
"width": 82,
Expand All @@ -175,9 +180,10 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 7,
"string": "1b"
"string": "1"
}
]
],
"filename": "both1.png"
},
{
"width": 82,
Expand All @@ -196,6 +202,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "both2_back",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -237,7 +244,7 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 3,
"string": "both2"
"string": "both2b"
},
{
"width": 82,
Expand All @@ -257,9 +264,10 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 7,
"string": "2"
"string": "2b"
}
]
],
"filename": "both2_back.png"
},
{
"width": 82,
Expand All @@ -278,6 +286,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "both2",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -319,7 +328,7 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 3,
"string": "both2b"
"string": "both2"
},
{
"width": 82,
Expand All @@ -339,9 +348,10 @@
"stroke_width": -1,
"image_scaling": "fitWidth",
"position": 7,
"string": "2b"
"string": "2"
}
]
],
"filename": "both2.png"
},
{
"width": 82,
Expand All @@ -360,6 +370,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "image only_image",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -423,7 +434,11 @@
"position": 7,
"string": "A"
}
]
],
"extra": {
"title": "only_image"
},
"filename": "image only_image.png"
},
{
"width": 82,
Expand All @@ -442,6 +457,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "image only_image",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -505,7 +521,11 @@
"position": 7,
"string": "A"
}
]
],
"extra": {
"title": "only_image"
},
"filename": "image only_image_0000.png"
},
{
"width": 82,
Expand All @@ -524,6 +544,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "11 only_text",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -587,7 +608,11 @@
"position": 3,
"string": "11"
}
]
],
"extra": {
"title": "only_text"
},
"filename": "11 only_text.png"
},
{
"width": 82,
Expand All @@ -606,6 +631,7 @@
"multiplier": 1,
"stroke_width": -1,
"image_scaling": "fitWidth",
"pretty_name": "22 only_text",
"images": [
{
"width": 82,
Expand Down Expand Up @@ -669,7 +695,11 @@
"position": 3,
"string": "22"
}
]
],
"extra": {
"title": "only_text"
},
"filename": "22 only_text.png"
}
]
}
3 changes: 3 additions & 0 deletions testdata/prototype.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"stroke_color": "black",
"image_scaling": "fitWidth",
"font_path": "../assets/BebasNeue-Regular.ttf",
"position_number_for_filename": 3,
"prototypes": {
"both": {
"text_prototypes": [
Expand All @@ -40,6 +41,7 @@
}
},
"only_image": {
"extra": { "title": "only_image" },
"texts": [
{ "position": 3, "string": "image" },
{ "position": 7, "string": "A" }
Expand All @@ -52,6 +54,7 @@
]
},
"only_text": {
"extra": { "title": "only_text" },
"text_prototypes": [
{
"position": 11,
Expand Down

0 comments on commit 812f2d4

Please sign in to comment.