2024-03-31 18:03:57 +02:00
# CORE FRAMEWORK TEST FILE
# Copyright (c) 2024 The StarOpenSource Project & Contributors
# Licensed under the GNU Affero General Public License v3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-03-29 02:41:36 +01:00
extends ' res://tests/unitbase.gd '
2024-03-28 15:18:34 +01:00
# byte2mib
func test_byte2mib ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : int = 51758516
var test_out : float = 49.36076736450195
var test_out_flat : float = 49.0
2024-03-31 16:20:34 +02:00
if core . 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 . misc . byte2mib ( test_in , false ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-31 16:20:34 +02:00
if core . 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 . misc . byte2mib ( test_in , true ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# mib2byte
func test_mib2byte ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : float = 49.36076736450195
var test_out : float = 51758516.0
var test_out_flat : float = test_out
2024-03-31 16:20:34 +02:00
if core . 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 . misc . mib2byte ( test_in , false ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-31 16:20:34 +02:00
if core . 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 . misc . mib2byte ( test_in , true ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# mib2gib
func test_mib2gib ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : float = 1500
var test_out : float = 1.46484375
var test_out_flat : float = 1.0
2024-03-31 16:20:34 +02:00
if core . 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 . misc . mib2gib ( test_in , false ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-31 16:20:34 +02:00
if core . 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 . misc . mib2gib ( test_in , true ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# gib2mib
func test_gib2mib ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : float = 1.46484375
var test_out : float = 1500.0
var test_out_flat : float = 1500.0
2024-03-31 16:20:34 +02:00
if core . 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 . misc . gib2mib ( test_in , false ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-31 16:20:34 +02:00
if core . 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 . misc . gib2mib ( test_in , true ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# format_stringarray
func test_format_stringarray ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : Array [ String ] = [ " StarOpenSource " , " JeremyStarTM " , " Contributors " ]
var test_out : String = " StarOpenSource, JeremyStarTM & Contributors "
2024-03-31 16:20:34 +02:00
if core . 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 . misc . format_stringarray ( test_in ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# format_stringarray (chaotic)
func test_format_stringarray_chaotic ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : Array [ String ] = [ " StarOpenSource " , " JeremyStarTM " , " Contributors " ]
var test_out : String = " aaaaStarOpenSourcebbbb$#!TaaaaJeremyStarTMbbbb :3 aaaaContributorsbbbb "
2024-03-31 16:20:34 +02:00
if core . 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 . misc . format_stringarray ( test_in ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# array_to_stringarray & stringarray_to_array
func test_array_stringarray_conversion ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# Variables
var test_in : Array = [ " StarOpenSource " , " JeremyStarTM " , " Contributors " ]
var test_out : Array [ String ] = [ " StarOpenSource " , " JeremyStarTM " , " Contributors " ]
2024-03-31 16:20:34 +02:00
if core . misc . stringarray_to_array ( core . 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 . misc . stringarray_to_array ( core . misc . array_to_stringarray ( test_in ) ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-03-28 15:18:34 +01:00
# get_center
func test_get_center ( ) - > void :
# Init CORE
2024-03-31 16:20:34 +02:00
await load_framework ( )
2024-03-28 15:18:34 +01:00
# 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 )
2024-03-31 16:20:34 +02:00
if core . 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 . misc . stringarray_to_array ( core . misc . get_center ( test_in_parent , test_in_child ) ) ) + " ' ) " )
2024-03-28 15:18:34 +01:00
return
2024-03-29 02:53:16 +01:00
rok ( )
2024-04-15 21:52:27 +02:00
# stringify_variables
func test_stringify_variables ( ) - > void :
# Init CORE
await load_framework ( )
# Variables
2024-04-23 21:02:11 +02:00
var test_in_string : String = " null= % null % \n bool= % bool % \n int= %i nt % \n float= %f loat % \n string= %s tring % \n stringname= %s tringname % \n color= %c olor % \n array= % array % \n dict= %d ictionary % \n nodepath= % nodepath % \n vec2= % vector2 % \n vec2i= % vector2i % \n rect2= %r ect2 % \n rect2i= %r ect2i % \n trans2d= % transform2d % \n vec3= % vector3 % \n vec3i= % vector3i % \n plane= % plane % \n quarternion= % quaternion % \n aabb= % aabb % \n trans3d= % transform3d % \n basis= % basis % \n projection= % projection % \n vec4= % vector4 % \n vec4i= % vector4i % "
2024-04-15 21:52:27 +02:00
var test_in_args : Dictionary = { " null " : null , " bool " : true , " int " : 505 , " float " : 505.69 , " string " : " some string " , " stringname " : " some string name " , " color " : Color ( " #d60532 " ) , " rid " : RenderingServer . get_white_texture ( ) , " array " : [ " item1 " , " item2 " , true , 4 ] , " dictionary " : { " key0 " : true , 1 : " key2 " } , " nodepath " : NodePath ( " /root/CORE " ) , " callable " : func ( ) - > void : pass , " signal " : core . logger . log_event , " vector2 " : Vector2 ( PI , TAU ) , " vector2i " : Vector2i ( 505 , 69 ) , " rect2 " : Rect2 ( 1.51 , 2.56 , 3.89 , 4.11 ) , " rect2i " : Rect2i ( 1 , 2 , 3 , 4 ) , " transform2d " : Transform2D ( 1.5 , Vector2 ( 2.1 , 2.2 ) , 3.6 , Vector2 ( 4.1 , 4.2 ) ) , " vector3 " : Vector3 ( 59.666 , NAN , INF ) , " vector3i " : Vector3i ( 505 , 69 , 1713208182 ) , " plane " : Plane ( Vector3 ( 1.5 , 2.5 , 3.5 ) , 55.7777 ) , " quaternion " : Quaternion ( 1.55 , 2.7812 , 3.671 , 4.8871 ) , " aabb " : AABB ( Vector3 ( 1.1 , 1.2 , 1.3 ) , Vector3 ( 2.1 , 2.2 , 2.3 ) ) , " transform3d " : Transform3D ( Basis ( Vector3 ( 1.11 , 1.12 , 1.13 ) , Vector3 ( 1.21 , 1.22 , 1.23 ) , Vector3 ( 1.31 , 1.32 , 1.33 ) ) , Vector3 ( 2.1 , 2.2 , 2.3 ) ) , " basis " : Basis ( Vector3 ( 1.1358 , 1.268718 , 1.35818 ) , Vector3 ( 2.1481 , 2.258819 , 2.3718 ) , Vector3 ( 3.1658581 , 3.2581587 , 3.357158 ) ) , " projection " : Projection ( Transform3D ( Basis ( Vector3 ( 1.11 , 1.12 , 1.13 ) , Vector3 ( 1.21 , 1.22 , 1.23 ) , Vector3 ( 1.31 , 1.32 , 1.33 ) ) , Vector3 ( 2.1 , 2.2 , 2.3 ) ) ) , " vector4 " : Vector4 ( 1.55158 , 2.517571 , 3.58157 , 4.51857185 ) , " vector4i " : Vector4i ( 1 , 2 , 3 , 4 ) }
2024-04-23 21:02:11 +02:00
var test_out : String = " null= ' null ' \n bool= ' (bool) true ' \n int= ' (int) 505 ' \n float= ' (float) 505.69 ' \n string= ' (string) \" some string \" ' \n stringname= ' (string) \" some string name \" ' \n color= ' (color) r=(int) 214 g=(int) 5 b=(int) 50 a=(int) 255 ' \n array= ' (array) [ (string) \" item1 \" , (string) \" item2 \" , (bool) true, (int) 4 ] ' \n dict= ' (dictionary) { (string) \" key0 \" : (bool) true, (int) 1 } ' \n nodepath= ' (nodepath) /root/CORE ' \n vec2= ' (vector2) x=(float) 3.14159274101257 y=(float) 6.28318548202515 ' \n vec2i= ' (vector2i) x=(int) 505 y=(int) 69 ' \n rect2= ' (rect2) size=(vector2) x=(float) 3.89000010490417 y=(float) 4.1100001335144 pos=(vector2) x=(float) 1.50999999046326 y=(float) 2.55999994277954 end=(vector2) x=(float) 5.40000009536743 y=(float) 6.67000007629395 ' \n rect2i= ' (rect2i) size=(vector2i) x=(int) 3 y=(int) 4 pos=(vector2i) x=(int) 1 y=(int) 2 end=(vector2i) x=(int) 4 y=(int) 6 ' \n trans2d= ' (transform2d) x=(vector2) x=(float) 0.14854811131954 y=(float) 2.09473943710327 y=(vector2) x=(float) 2.03679251670837 y=(float) 0.83155089616776 origin=(vector2) x=(float) 4.09999990463257 y=(float) 4.19999980926514 ' \n vec3= ' (vector3) x=(float) 59.6660003662109 y=(float) nan z=(float) inf ' \n vec3i= ' (vector3i) x=(int) 505 y=(int) 69 z=(int) 1713208182 ' \n plane= ' (plane) x=(float) 1.5 y=(float) 2.5 z=(float) 3.5 d=(float) 55.7776985168457 normal=(vector3) x=(float) 1.5 y=(float) 2.5 z=(float) 3.5 ' \n quarternion= ' (quaternion) x=(float) 1.54999995231628 y=(float) 2.78119993209839 z=(float) 3.6710000038147 w=(float) 4.88710021972656 ' \n aabb= ' (aabb) size=(vector3) x=(float) 2.09999990463257 y=(float) 2.20000004768372 z=(float) 2.29999995231628 pos=(vector3) x=(float) 1.10000002384186 y=(float) 1.20000004768372 z=(float) 1.29999995231628 end=(vector3) x=(float) 3.19999980926514 y=(float) 3.40000009536743 z=(float) 3.59999990463257 ' \n trans3d= ' (transform3d) basis=(basis) x=(vector3) x=(float) 1.11000001430511 y=(float) 1.12000000476837 z=(float) 1.12999999523163 y=(vector3) x=(float) 1.21000003814697 y=(float) 1.22000002861023 z=(float) 1.23000001907349 z=(vector3) x=(float) 1.30999994277954 y=(float) 1.32000005245209 z=(float) 1.33000004291534 origin=(vector3) x=(float) 2.09999990463257 y=(float) 2.20000004768372 z=(float) 2.29999995231628 ' \n basis= ' (basis) x=(vector3) x=(float) 1.13580000400543 y=(float) 1.26871800422668 z=(float) 1.35818004608154 y=(vector3) x=(float) 2.14809989929199 y=(float) 2.25881910324097 z=(float) 2.3717999458313 z=(vector3) x=(float) 3.16585803031921 y=(float) 3.25815868377686 z=(float) 3.35715794563293 ' \n projection= ' (projection) x=(vector4) x=(float) 1.11000001430511 y=(float) 1.12000000476837 z=(float) 1.12999999523163 w=(float) 0 y=(vector4) x=(float) 1.21000003814697 y=(float) 1.22000002861023 z=(float) 1.23000001907349 w=(float) 0 z=(vector4) x=(float) 1.30999994277954 y=(float) 1.32000005245209 z=(float) 1.33000004291534 w=(float) 0 w=(vector4) x=(float) 2.09999990463257 y=(float) 2.20000004768372 z=(float) 2.29999995231628 w=(float) 1 ' \n vec4= ' (vector4) x=(float) 1.55157995223999 y=(float) 2.51757097244263 z=(float) 3.58156991004944 w=(float) 4.5185718536377 ' \n vec4i= ' (vector4i) x=(int) 1 y=(int) 2 z=(int) 3 w=(int) 4 ' "
2024-04-15 21:52:27 +02:00
var test_result : String = core . misc . stringify_variables ( test_in_string , test_in_args )
if test_result != test_out :
lerror ( " Got invalid test result: " )
2024-04-23 21:02:11 +02:00
lerror ( " in (string) -> " )
for line in test_in_string . split ( " \n " ) :
print_rich ( " [color=red]---> " + line + " [/color] " )
await get_tree ( ) . create_timer ( 0.05 ) . timeout # output overflow workaround
2024-04-15 21:52:27 +02:00
lerror ( " in (args) -> " + str ( test_in_args ) )
await get_tree ( ) . create_timer ( 1 ) . timeout # output overflow workaround
2024-04-23 21:02:11 +02:00
lerror ( " expected -> " )
for line in test_out . split ( " \n " ) :
print_rich ( " [color=red]---> " + line + " [/color] " )
await get_tree ( ) . create_timer ( 0.05 ) . timeout # output overflow workaround
lerror ( " got -> " )
for line in test_result . split ( " \n " ) :
print_rich ( " [color=red]---> " + line + " [/color] " )
await get_tree ( ) . create_timer ( 0.05 ) . timeout # output overflow workaround
2024-04-15 21:52:27 +02:00
rerror ( " Test did not return the right value (check logs) " )
return
2024-04-23 21:02:11 +02:00
rok ( " All types except RIDs, Callables and Signals have been verified as working. " )