CORE/tests/unit/misc.gd

142 lines
5.3 KiB
GDScript

extends 'res://tests/unitbase.gd'
# byte2mib
func test_byte2mib() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: int = 51758516
var test_out: float = 49.36076736450195
var test_out_flat: float = 49.0
if core_test.misc.byte2mib(test_in, false) != test_out:
rerror("Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.byte2mib(test_in, false)) + "')")
return
if core_test.misc.byte2mib(test_in, true) != test_out_flat:
rerror("Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.byte2mib(test_in, true)) + "')")
return
rok()
# mib2byte
func test_mib2byte() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: float = 49.36076736450195
var test_out: float = 51758516.0
var test_out_flat: float = test_out
if core_test.misc.mib2byte(test_in, false) != test_out:
rerror("Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.mib2byte(test_in, false)) + "')")
return
if core_test.misc.mib2byte(test_in, true) != test_out_flat:
rerror("Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.mib2byte(test_in, true)) + "')")
return
rok()
# mib2gib
func test_mib2gib() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: float = 1500
var test_out: float = 1.46484375
var test_out_flat: float = 1.0
if core_test.misc.mib2gib(test_in, false) != test_out:
rerror("Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.mib2gib(test_in, false)) + "')")
return
if core_test.misc.mib2gib(test_in, true) != test_out_flat:
rerror("Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.mib2gib(test_in, true)) + "')")
return
rok()
# gib2mib
func test_gib2mib() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: float = 1.46484375
var test_out: float = 1500.0
var test_out_flat: float = 1500.0
if core_test.misc.gib2mib(test_in, false) != test_out:
rerror("Non-flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.gib2mib(test_in, false)) + "')")
return
if core_test.misc.gib2mib(test_in, true) != test_out_flat:
rerror("Flat test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.gib2mib(test_in, true)) + "')")
return
rok()
# format_stringarray
func test_format_stringarray() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
var test_out: String = "StarOpenSource, JeremyStarTM & Contributors"
if core_test.misc.format_stringarray(test_in) != test_out:
rerror("Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.format_stringarray(test_in)) + "')")
return
rok()
# format_stringarray (chaotic)
func test_format_stringarray_chaotic() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
var test_out: String = "aaaaStarOpenSourcebbbb$#!TaaaaJeremyStarTMbbbb :3 aaaaContributorsbbbb"
if core_test.misc.format_stringarray(test_in, "aaaa", "bbbb", "$#!T", " :3 ") != test_out:
rerror("Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.format_stringarray(test_in)) + "')")
return
rok()
# array_to_stringarray & stringarray_to_array
func test_array_stringarray_conversion() -> void:
# Init CORE
var core_test: Core = await load_framework()
# Variables
var test_in: Array = ["StarOpenSource", "JeremyStarTM", "Contributors"]
var test_out: Array[String] = ["StarOpenSource", "JeremyStarTM", "Contributors"]
if core_test.misc.stringarray_to_array(core_test.misc.array_to_stringarray(test_in)) != test_out:
rerror("Test did not return the right value (in '" + str(test_in) + "', expected '" + str(test_out) + "', got '" + str(core_test.misc.stringarray_to_array(core_test.misc.array_to_stringarray(test_in))) + "')")
return
rok()
# get_center
func test_get_center() -> void:
# Init CORE
var core_test = await 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_test.misc.get_center(test_in_parent, test_in_child) != test_out:
rerror("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_test.misc.stringarray_to_array(core_test.misc.get_center(test_in_parent, test_in_child))) + "')")
return
rok()