to save up a progress

This commit is contained in:
2026-09-19 23:21:09 +03:00
parent 78cdfa3beb
commit e51ffde305
16 changed files with 267 additions and 13 deletions
+47 -4
View File
@@ -9,6 +9,7 @@ import (
"os/exec"
"testing"
"time"
"reflect"
"git.nkpl.cc/twocookedfaggots/imageutils"
)
@@ -17,6 +18,8 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
const factor = 0.75
func callImage(img image.Image) {
for y := 0; y < img.Bounds().Dy(); y++ {
for x := 0; x < img.Bounds().Dx(); x++ {
@@ -38,14 +41,14 @@ func TestGrid(t *testing.T) {
n := uint8(rand.Int() % 256)
t.Log(n)
img := imageutils.Scale(1<<6, grid{color.Gray{n}})
img := imageutils.Scale(grid{color.Gray{n}, factor}, 1<<6)
err = png.Encode(w, img)
if err != nil {
t.Fatal(err)
}
callImage(grid{color.Gray{4}})
callImage(grid{color.Gray{0}})
callImage(grid{color.Gray{4}, factor})
callImage(grid{color.Gray{0}, factor})
}
func TestDithering(t *testing.T) {
@@ -66,8 +69,48 @@ func TestDithering(t *testing.T) {
t.Fatal(err)
}
err = png.Encode(w, Dithering{img})
err = png.Encode(w, Dithering{img, factor})
if err != nil {
t.Fatal(err)
}
}
func TestRangeStruct(t *testing.T){
s := Dithering{image.Rectangle{},0}
value := reflect.ValueOf(s)
if value.Kind() == reflect.Ptr {
value = value.Elem()
}
if value.Kind() != reflect.Struct {
t.Log("Provided value is not a struct")
}
tp := value.Type()
for i := 0; i < value.NumField(); i++ {
fieldName := tp.Field(i).Name
fieldValue := value.Field(i)
if !fieldValue.CanInterface() {
t.Logf("Field %s is unexported\n", fieldName)
continue
}
if fieldValue.Kind() == reflect.Ptr {
fieldValue = fieldValue.Elem()
}
/*
if fieldValue.Kind() == reflect.Interface {
fieldValue = fieldValue.Elem()
}
*/
actualValue := fieldValue.Interface()
switch v := actualValue.(type) {
case float64:
t.Logf("Field '%s' is a float64.\n", fieldName)
case image.Image:
t.Logf("Field '%s' is a image.Image. Value: %q\n", fieldName, v)
default:
t.Logf("Field '%s' has an unhandled type: %T\n", fieldName, v)
}
}
}