Commit b60a2cb5 authored by adud's avatar adud

add a unit test for the workspace

One bug corrected: children were fit in a rectangle of the size of the WorkSpace
parent a99937a2
......@@ -7,5 +7,14 @@
.. warning::
For the moment, SignSymb is only a dummy text display that is used to test
the :ref:`WorkSpace`
the :class:`WorkSpace`
.. class:: SignSymb
A representation of the sign shown to the user.
.. function:: set_text(String st)
Setter for the symbol text
:param: st(String) the value to set
extends Control
func set_text(st):
$Text.set_text(st)
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
[gd_scene format=2]
[gd_scene load_steps=2 format=2]
[ext_resource path="res://SignSymb.gd" type="Script" id=1]
[node name="SignSymb" type="Control"]
margin_right = 35.0
margin_right = 100.0
margin_bottom = 14.0
script = ExtResource( 1 )
__meta__ = {
"_edit_group_": true
}
[node name="Label" type="Label" parent="."]
margin_right = 35.0
[node name="Text" type="Label" parent="."]
margin_right = 100.0
margin_bottom = 14.0
mouse_filter = 1
mouse_default_cursor_shape = 1
text = "A....Z"
text = "Aristotélicien"
align = 1
clip_text = true
extends Container
const DEBUG = 1
# WorkSpace
# handles speech display
......@@ -17,37 +19,61 @@ var text = []
# puts the SignSymbs in the grid
func dispose_childs():
if text == []:
return
# Assumption: all symbols have same size
var symb_size = text[0].get_size()
var space = symb_size + sep
var pos = Vector2(0, 0)
print(symb_size, space, pos)
for symb in text:
if pos.x + symb_size.x > rect_size.x: # Line Wrapping
pos.y += space.y
pos.x = 0
print(pos.x)
fit_child_in_rect(symb, Rect2(pos, rect_size))
fit_child_in_rect(symb, Rect2(pos, symb_size))
pos.x += space.x
func test():
func test(n):
var symb
for i in range(20):
var pos_in_line
var line_number
var est_pos
var real_pos
var dtext = ["Hello", "World", "Lorem", "Ipsum"]
for _i in range(n): # underscore is for preventing unused var warnings
symb = SignSymb.instance()
add_child(symb)
text.append(symb)
for i in range(len(dtext)):
text[i].set_text(dtext[i])
dispose_childs()
# test the naive position of elements (no linebreak)
var symb_size = text[0].get_size()
var words_per_line = int((rect_size + sep).x / (symb_size + sep).x)
for i in range(len(text)):
line_number = i / words_per_line
pos_in_line = i % words_per_line
est_pos = Vector2(pos_in_line * (symb_size + sep).x,
line_number * (symb_size + sep).y)
real_pos = text[i].get_position()
if real_pos != est_pos:
print("Workspace Test Failure, pos should be: ", est_pos,
"it is: ", real_pos)
# Called when the node enters the scene tree for the first time.
func _ready():
test()
if DEBUG:
test(20)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment