Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GD-347: Allow to compare real vs int typed dictionary #347

Closed
ZodmanPerth opened this issue Dec 23, 2022 · 7 comments · Fixed by #352
Closed

GD-347: Allow to compare real vs int typed dictionary #347

ZodmanPerth opened this issue Dec 23, 2022 · 7 comments · Fixed by #352
Assignees
Labels
bug Something isn't working
Milestone

Comments

@ZodmanPerth
Copy link

The used Godot version:
v3.5.1.stable.official [6fed1ffa3]

OS including version:
Windows 11

Describe the bug
I'm using a dictionary in a parameterised test in GdUnit3 2.3.1. The dictionary contains key/value pairs of type string/double.
When I define my expected value dictionary, I define the values using whole numbers (i.e. without the decimal point).
The difference report shows the actual values are identical to the expected values (see image).
image
The expected values in the above test run were defined as { left = 50, top = 50, right = 50, bottom = 50 }.
As a workaround, if I define my expected values as { left = 50.0, top = 50.0, right = 50.0, bottom = 50.0 } then the test passes.

Steps to Reproduce

  1. Create a parameterised test containing a Dictionary expected value containing key/value pairs of type string/double.
  2. Create a test parameter containing valid integer values
  3. Run the test
  4. Observe the assert fails but the "expecting" is the same as the "actual" in the report.
@ZodmanPerth ZodmanPerth added the bug Something isn't working label Dec 23, 2022
@MikeSchulze
Copy link
Owner

Hello, if you compare two dictionaries with different types, the result is always false.

Just try this

	var x := { "left" : 50, "top" : 50, "right" : 50, "bottom" : 50 }
	var y := { "left" : 50.0, "top" : 50.0, "right" : 50.0, "bottom" : 50.0  }
	prints(x == y)

is same result as use:
assert_dict({ "left" : 50, "top" : 50, "right" : 50, "bottom" : 50 }).is_equal({ "left" : 50.0, "top" : 50.0, "right" : 50.0, "bottom" : 50.0 })

Can you please add an example of your test for better understanding.

@ZodmanPerth
Copy link
Author

Oh you're right. My apologies. I expected x == y to be true and that Godot would typecase the values to be the same at runtime.
This is not a bug then. Please close.

@MikeSchulze
Copy link
Owner

hi @ZodmanPerth can you please add your testcase to fully understand your issue.

@ZodmanPerth
Copy link
Author

ZodmanPerth commented Dec 26, 2022

This test passes:

func test_riffing() -> void:
	assert_that(50.0).is_equal(50)

Only the last test here passes. I expected them all to.
I expect that implicit casing would occur between 50 and 50.0 as it does in the simple case.

func test_dictionary_types(
	value : Dictionary,
	expected : Dictionary,
	test_parameters : Array = [
		[{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0},	{ top = 50, 	bottom = 50,	left = 50,  	right = 50}],
		[{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0},	{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0}],
		[{ top = 50,	bottom = 50,	left = 50,  	right = 50},	{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0}],
		[{ top = 50,	bottom = 50,	left = 50,  	right = 50},	{ top = 50, 	bottom = 50,	left = 50,  	right = 50}],
	]
) -> void:
	assert_that(value).is_equal(expected)

They also don't produce any failure report:

image

@MikeSchulze MikeSchulze changed the title Double type values in dictionaries in parameterised tests don't compare quite right GD-347: Double type values in dictionaries in parameterised tests don't compare quite right Dec 27, 2022
@MikeSchulze MikeSchulze added this to the v2.3.2 milestone Dec 27, 2022
@MikeSchulze
Copy link
Owner

MikeSchulze commented Dec 27, 2022

The lack of bug reports is definitely a bug.
But the comparison of dictionarys with different types is Godot conform.

@MikeSchulze
Copy link
Owner

MikeSchulze commented Dec 27, 2022

Update.
I found a bug on the UI side, the tree items were not unique and therefore updated incorrectly.
For the comparison problem I added a new property that allows to compare values in a type safe way.

func test_dictionary_div_number_types(
	value : Dictionary,
	expected : Dictionary,
	test_parameters : Array = [
		[{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0},	{ top = 50, 	bottom = 50,	left = 50,  	right = 50}],
		[{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0},	{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0}],
		[{ top = 50,	bottom = 50,	left = 50,  	right = 50},	{ top = 50.0,	bottom = 50.0,	left = 50.0,	right = 50.0}],
		[{ top = 50,	bottom = 50,	left = 50,  	right = 50},	{ top = 50, 	bottom = 50,	left = 50,  	right = 50}],
	]
) -> void:
	# allow to compare type unsave
	ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, false)
	assert_that(value).is_equal(expected)

You can set this property explecit on a test or global at the settings
image

@MikeSchulze MikeSchulze linked a pull request Dec 27, 2022 that will close this issue
@MikeSchulze MikeSchulze changed the title GD-347: Double type values in dictionaries in parameterised tests don't compare quite right GD-347: Allow to compare real vs int typed dictionary Dec 27, 2022
@github-project-automation github-project-automation bot moved this to Done in GdUnit3 Dec 27, 2022
@ZodmanPerth
Copy link
Author

Oooh nice. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants