Add unit testing for misc.gd (partial #11)
This commit is contained in:
parent
5dfac5458a
commit
3bcc18df82
1 changed files with 166 additions and 0 deletions
166
tests/unit/misc.gd
Normal file
166
tests/unit/misc.gd
Normal file
|
@ -0,0 +1,166 @@
|
||||||
|
extends BessereTestsTest
|
||||||
|
|
||||||
|
# Callbacks
|
||||||
|
var callback: String = ""
|
||||||
|
|
||||||
|
# Utils
|
||||||
|
var utils: Node = CoreTestUtils.new()
|
||||||
|
|
||||||
|
func before_all() -> void: add_child(utils)
|
||||||
|
func after_all() -> void: remove_child(utils)
|
||||||
|
|
||||||
|
# Unload framework after each test
|
||||||
|
func after_each() -> void: utils.unload_framework()
|
||||||
|
|
||||||
|
# byte2mib
|
||||||
|
func test_byte2mib() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: int = 51758516
|
||||||
|
var test_out: float = 49.36076736450195
|
||||||
|
var test_out_flat: float = 49.0
|
||||||
|
|
||||||
|
if core.misc.byte2mib(test_in, false) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.byte2mib(test_in, false)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
if core.misc.byte2mib(test_in, true) != test_out_flat:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.byte2mib(test_in, true)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# mib2byte
|
||||||
|
func test_mib2byte() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: float = 49.36076736450195
|
||||||
|
var test_out: float = 51758516.0
|
||||||
|
var test_out_flat: float = test_out
|
||||||
|
|
||||||
|
if core.misc.mib2byte(test_in, false) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.mib2byte(test_in, false)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
if core.misc.mib2byte(test_in, true) != test_out_flat:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.mib2byte(test_in, true)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# mib2gib
|
||||||
|
func test_mib2gib() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: float = 1500
|
||||||
|
var test_out: float = 1.46484375
|
||||||
|
var test_out_flat: float = 1.0
|
||||||
|
|
||||||
|
if core.misc.mib2gib(test_in, false) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.mib2gib(test_in, false)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
if core.misc.mib2gib(test_in, true) != test_out_flat:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.mib2gib(test_in, true)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# gib2mib
|
||||||
|
func test_gib2mib() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: float = 1.46484375
|
||||||
|
var test_out: float = 1500.0
|
||||||
|
var test_out_flat: float = 1500.0
|
||||||
|
|
||||||
|
if core.misc.gib2mib(test_in, false) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.gib2mib(test_in, false)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
if core.misc.gib2mib(test_in, true) != test_out_flat:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.gib2mib(test_in, true)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# format_stringarray
|
||||||
|
func test_format_stringarray() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
|
||||||
|
var test_out: String = "StarOpenSource, JeremyStarTM & Contributors"
|
||||||
|
|
||||||
|
if core.misc.format_stringarray(test_in) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.format_stringarray(test_in)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# format_stringarray (chaotic)
|
||||||
|
func test_format_stringarray_chaotic() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
|
||||||
|
var test_out: String = "aaaaStarOpenSourcebbbb$#!TaaaaJeremyStarTMbbbb :3 aaaaContributorsbbbb"
|
||||||
|
|
||||||
|
if core.misc.format_stringarray(test_in, "aaaa", "bbbb", "$#!T", " :3 ") != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.format_stringarray(test_in)) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# array_to_stringarray & stringarray_to_array
|
||||||
|
func test_array_stringarray_conversion() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core: Core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in: Array = ["StarOpenSource", "JeremyStarTM", "Contributors"]
|
||||||
|
var test_out: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
|
||||||
|
|
||||||
|
if core.misc.stringarray_to_array(core.misc.array_to_stringarray(test_in)) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core.misc.stringarray_to_array(core.misc.array_to_stringarray(test_in))) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
||||||
|
|
||||||
|
# get_center
|
||||||
|
func test_get_center() -> void:
|
||||||
|
# Init CORE
|
||||||
|
var core = await utils.load_framework()
|
||||||
|
|
||||||
|
# Variables
|
||||||
|
var test_in_parent: Vector2 = Vector2(5919.591, 6815.9514)
|
||||||
|
var test_in_child: Vector2 = Vector2(69.69, 666.0)
|
||||||
|
var test_out: Vector2 = Vector2(test_in_parent.x/2-test_in_child.x/2, test_in_parent.y/2-test_in_child.y/2)
|
||||||
|
|
||||||
|
if core.misc.get_center(test_in_parent, test_in_child) != test_out:
|
||||||
|
test_status = 2
|
||||||
|
test_message = "Test did not return the right value (in (parent) '" + str(test_in_parent) + "', in (child) '" + str(test_in_child) + "', expected '" + str(test_out) + "', got '" + str(core.misc.stringarray_to_array(core.misc.get_center(test_in_parent, test_in_child))) + "')"
|
||||||
|
return
|
||||||
|
|
||||||
|
test_status = 0
|
Loading…
Reference in a new issue