addons/gut/parameter_factory.gd

Inherits: RefCounted

Creates parameter structures for parameterized tests.

Description

This is a static class accessible in a GutTest script through GutTest.ParameterFactory. It contains methods for constructing parameters to be used in parameterized tests. It currently only has one, if you have anyu ideas for more, make an issue. More of them would be great since I prematurely decided to make this static class and it has such a long name. I’d feel a lot better about it if there was more in here.

Additional Helper Ideas?

  • File. IDK what it would look like. csv maybe.

  • Random values within a range?

  • All int values in a range or add an optioanal step.

Methods

Variant

named_parameters(names, values) static


Method Descriptions

Variant named_parameters(names, values) static 🔗

Creates an array of dictionaries. It pairs up the names array with each set of values in values. If more names than values are specified then the missing values will be filled with nulls. If more values than names are specified those values will be ignored. Example:

create_named_parameters(['a', 'b'], [[1, 2], ['one', 'two']]) returns
   [{a:1, b:2}, {a:'one', b:'two'}]

This allows you to increase readability of your parameterized tests:

var params = create_named_parameters(['a', 'b'], [[1, 2], ['one', 'two']])
func test_foo(p = use_parameters(params)):
   assert_eq(p.a, p.b)

Parameters:

  • names: an array of names to be used as keys in the dictionaries

  • values: an array of arrays of values.