CORE/tests/unit/misc.gd

155 lines
5.7 KiB
GDScript3
Raw Normal View History

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:
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_test.misc.byte2mib(test_in, false)) + "')"
return
if core_test.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_test.misc.byte2mib(test_in, true)) + "')"
return
test_status = 0
# 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:
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_test.misc.mib2byte(test_in, false)) + "')"
return
if core_test.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_test.misc.mib2byte(test_in, true)) + "')"
return
test_status = 0
# 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:
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_test.misc.mib2gib(test_in, false)) + "')"
return
if core_test.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_test.misc.mib2gib(test_in, true)) + "')"
return
test_status = 0
# 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:
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_test.misc.gib2mib(test_in, false)) + "')"
return
if core_test.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_test.misc.gib2mib(test_in, true)) + "')"
return
test_status = 0
# 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:
test_status = 2
test_message = "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
test_status = 0
# 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:
test_status = 2
test_message = "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
test_status = 0
# 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:
test_status = 2
test_message = "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
test_status = 0
# 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:
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_test.misc.stringarray_to_array(core_test.misc.get_center(test_in_parent, test_in_child))) + "')"
return
test_status = 0