62 lines
2.4 KiB
Nim
62 lines
2.4 KiB
Nim
import unittest
|
|
import arraymancer
|
|
import tensorCeral
|
|
import cl
|
|
import implementation
|
|
import math
|
|
import sugar
|
|
import sequtils
|
|
import streams
|
|
import strutils
|
|
import random
|
|
import os
|
|
randomize()
|
|
suite "encoding":
|
|
echo "this is the encoding suite!"
|
|
test "Decode Test":
|
|
let resolution = 600
|
|
let pad = 9
|
|
let maxBytes = (resolution^2 / (pad+1)^2)-256
|
|
doAssert maxBytes mod 1 == 0
|
|
discard existsOrCreateDir("./in/")
|
|
discard existsOrCreateDir("./in/0/")
|
|
let pallet = genColorMatrix()
|
|
let garbage = newStringStream(collect(for x in 1 .. maxBytes.int:
|
|
(parseHexStr(toHex(rand(0 .. 255).byte)))).join(""))
|
|
let inputData = encodeImage(9, 0, garbage, pallet)[1]
|
|
let outputData = fromPng("in/0/in0.png" , 9, 0, false)
|
|
check inputData == outputData
|
|
test "tensorCerial":
|
|
var input = newStringStream("")
|
|
|
|
serializeTensor(input,
|
|
[pallet.shape, inputData.shape, outputData.shape],
|
|
[pallet.toFlatSeq(), inputData.toFlatSeq(), outputData.toFlatSeq()], false)
|
|
|
|
let serializationTest = deSerializeTensors(input)
|
|
|
|
let toFloat = (
|
|
pallet.toFlatSeq().map(x=>x.float32).toTensor().reshape(pallet.shape),
|
|
inputData.toFlatSeq().map(x=>x.float32).toTensor().reshape(inputData.shape),
|
|
outputdata.toFlatSeq().map(x=>x.float32).toTensor().reshape(outputData.shape)
|
|
)
|
|
|
|
check serializationTest == toFloat
|
|
input.setPosition(0)
|
|
test "implementation test":
|
|
var implementOutput = newStringStream("")
|
|
discard getBestBytes(input, implementOutput)
|
|
implementOutput.setPosition(0)
|
|
garbage.setPosition(0)
|
|
|
|
check garbage.readAll() == implementOutput.readAll()
|
|
test "convertFramesTest":
|
|
garbage.setPosition(0)
|
|
convertFrames((0, "outTemp.bin", garbage, true, ""))
|
|
#honestly if this works, theres no more testing needed, the rest would be implementation issues
|
|
#which are already checked....
|
|
#I guess it could be in more depth but its really hard tpo at this stage
|
|
discard deSerializeTensors(newFileStream("outTemp.bin"))[2]
|
|
removeFile("outTemp.bin")
|
|
|
|
|