From 561bad241f97f959867ca0f681ad89ab6486d18c Mon Sep 17 00:00:00 2001 From: AnidemDex Date: Wed, 12 Jun 2024 20:19:48 -0500 Subject: [PATCH 1/3] Create tests folder for gdunit2. Include a .gdignore file to avoid errors when importing the plugin without gdunit plugin --- tests/.gdignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/.gdignore diff --git a/tests/.gdignore b/tests/.gdignore new file mode 100644 index 0000000..e69de29 From 13eafd12a327db4a0c06c3e59ee3ad8365b0b3ef Mon Sep 17 00:00:00 2001 From: AnidemDex Date: Wed, 12 Jun 2024 20:20:12 -0500 Subject: [PATCH 2/3] Create Collection test suit --- tests/collection_test.gd | 83 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/collection_test.gd diff --git a/tests/collection_test.gd b/tests/collection_test.gd new file mode 100644 index 0000000..dfe9a7a --- /dev/null +++ b/tests/collection_test.gd @@ -0,0 +1,83 @@ +# GdUnit generated TestSuite +class_name CollectionTest +extends GdUnitTestSuite +@warning_ignore('unused_parameter') +@warning_ignore('return_value_discarded') + +# TestSuite generated from +const __source = 'res://addons/blockflow/collection.gd' + + +func test_add() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_insert() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_copy() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_move() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_erase() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_remove() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_clear() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_get_command() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_get_last_command() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_get_command_position() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_get_duplicated() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_has() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_find() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_size() -> void: + # remove this line and complete your test + assert_not_yet_implemented() + + +func test_is_empty() -> void: + # remove this line and complete your test + assert_not_yet_implemented() From 42690a5f34db080c3b52f57d4f2d2036113195f1 Mon Sep 17 00:00:00 2001 From: AnidemDex Date: Sat, 15 Jun 2024 18:03:14 -0500 Subject: [PATCH 3/3] Update Collection UnitTest. Update each method unit test. --- tests/collection_test.gd | 206 +++++++++++++++++++++++++++++++++------ 1 file changed, 175 insertions(+), 31 deletions(-) diff --git a/tests/collection_test.gd b/tests/collection_test.gd index dfe9a7a..46b7f5b 100644 --- a/tests/collection_test.gd +++ b/tests/collection_test.gd @@ -7,77 +7,221 @@ extends GdUnitTestSuite # TestSuite generated from const __source = 'res://addons/blockflow/collection.gd' +const CollectionClass = preload(__source) +const CommandClass = preload("res://addons/blockflow/commands/command.gd") + +class DummyCommand extends CommandClass: + func _get_name() -> StringName: return &"DummyCommand" + +class FakeCommand extends CommandClass: + func _get_name() -> StringName: return &"FakeCommand" + +var collection:CollectionClass + +func before_test() -> void: + collection = CollectionClass.new() + assert_array(collection.collection).is_empty() + func test_add() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var fake_command := CommandClass.new() + collection.add(fake_command) + + assert_array(collection.collection).is_not_empty().has_size(1) func test_insert() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var command_a := CommandClass.new() + var command_b := CommandClass.new() + var command_c := CommandClass.new() + + collection.add(command_a) + collection.add(command_c) + + assert_array(collection.collection).has_size(2)\ + .contains_exactly([command_a, command_c]) + + collection.insert(command_b, 1) + + assert_array(collection.collection).has_size(3)\ + .contains_exactly([command_a, command_b, command_c]) + func test_copy() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var dummy_command := DummyCommand.new() + collection.add(dummy_command) + + for i in 10: + var fake_command := FakeCommand.new() + collection.add(fake_command) + + collection.copy(dummy_command, 8) + assert_array(collection.collection).is_not_empty()\ + .contains([dummy_command]).has_size(12) + + assert_object(collection.collection[0]).is_instanceof(DummyCommand) + assert_object(collection.collection[1]).is_not_instanceof(DummyCommand) + assert_object(collection.collection[8]).is_instanceof(DummyCommand) func test_move() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + for i in 10: + collection.add(FakeCommand.new()) + + var dummy_command := DummyCommand.new() + collection.add(dummy_command) + assert_array(collection.collection).is_not_empty() + assert_bool(collection.collection.find(dummy_command) == 10).is_true() + + collection.move(dummy_command, 1) + assert_bool(collection.collection.find(dummy_command) == 1).is_true() func test_erase() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + for i in 10: + collection.add(FakeCommand.new()) + + assert_array(collection.collection).is_not_empty()\ + .has_size(10) + + collection.erase(collection.collection[-1]) + assert_array(collection.collection).is_not_empty()\ + .has_size(9) func test_remove() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + for i in 10: + collection.add(FakeCommand.new()) + + assert_array(collection.collection).is_not_empty()\ + .has_size(10) + + collection.remove(0) + assert_array(collection.collection).is_not_empty()\ + .has_size(9) func test_clear() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + for i in 10: + collection.add(FakeCommand.new()) + + assert_array(collection.collection).is_not_empty()\ + .has_size(10) + + collection.clear() + assert_array(collection.collection).is_empty() func test_get_command() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var command_a := CommandClass.new() + var command_b := CommandClass.new() + var command_c := CommandClass.new() + + collection.add(command_a) + collection.add(command_b) + collection.add(command_c) + + var result = collection.get_command(1) + assert_bool(result == command_a).is_false() + assert_bool(result == command_b).is_true() + assert_bool(result == command_c).is_false() func test_get_last_command() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var command_a := CommandClass.new() + var command_b := CommandClass.new() + var command_c := CommandClass.new() + + collection.add(command_a) + collection.add(command_b) + collection.add(command_c) + + var result = collection.get_last_command() + assert_bool(result == command_c).is_true() + assert_bool(result == command_a).is_false() func test_get_command_position() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + var expected_position := randi_range(0, 10) + var dummy_command := DummyCommand.new() + + for i in 10: + if i == expected_position: + collection.add(dummy_command) + continue + + collection.add(FakeCommand.new()) + + assert_array(collection.collection).is_not_empty()\ + .has_size(10) + + var result = collection.get_command_position(dummy_command) + assert_bool(result == expected_position).is_true() func test_get_duplicated() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + for i in 10: + collection.add(FakeCommand.new()) + var duplicated = collection.get_duplicated() + + assert_object(duplicated).is_not_same(collection) func test_has() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + + var command_a := FakeCommand.new() + var command_b := FakeCommand.new() + var command_c := FakeCommand.new() + + collection.add(command_a) + collection.add(command_b) + collection.add(command_c) + + assert_array(collection.collection).contains_same([command_b]) + assert_bool(collection.collection.has(command_b)) + assert_bool(collection.has(command_b)) func test_find() -> void: - # remove this line and complete your test - assert_not_yet_implemented() - + var expected_position := randi_range(0, 10) + var dummy_command := DummyCommand.new() + + for i in 10: + if i == expected_position: + collection.add(dummy_command) + continue + + collection.add(FakeCommand.new()) + + var result := collection.find(dummy_command) + + assert_bool(result == expected_position).is_true() + assert_bool(collection.find(FakeCommand.new()) != -1).is_false() func test_size() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + var expected_result := randi_range(1, 20) + for i in expected_result: + collection.add(FakeCommand.new()) + + assert_array(collection.collection).is_not_empty()\ + .has_size(expected_result) + + assert_int(collection.size()).is_equal(expected_result) func test_is_empty() -> void: - # remove this line and complete your test - assert_not_yet_implemented() + assert_array(collection.collection).is_empty() + assert_bool(collection.is_empty()).is_true()