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

Support set of Parameters #76

Open
rafaeltonholo opened this issue Nov 29, 2024 · 0 comments
Open

Support set of Parameters #76

rafaeltonholo opened this issue Nov 29, 2024 · 0 comments

Comments

@rafaeltonholo
Copy link
Contributor

Thank you for this great library! I would like to ask about adding support for a new feature.

I want to create a test case where I pass an input String along with an expected output data type that the subject in test will parse the string into another data type, in this situation, a FloatArray.

I noticed that the TestParameterInjector supports this feature through a set of parameters. Is there a way to achieve the same functionality with Burst?

I have tried several approaches to accomplish this, and while they work, they feel a bit off. Here's what I have attempted:

  1. Using a Pair<String, FloatArray>
  2. Using a data class to wrap the values
  3. Using a simple class

All three methods work, but the generated test names are quite unhelpful. For instance, the following test case:

@Burst
class SvgViewBoxTest {
    @Test
    fun testViewBoxWithSpacesAsSeparators(
        params: Pair<String, FloatArray> = burstValues(
            "0 0 120 120" to floatArrayOf(0f, 0f, 120f, 120f),
            "10 0 3000 120" to floatArrayOf(10f, 0f, 3000f, 120f),
            "0 0 0 1200" to floatArrayOf(0f, 0f, 0f, 1200f),
            "10 150 500 20" to floatArrayOf(10f, 150f, 500f, 20f),
        ),
    ) {
        val (viewBox, expected) = params
        println("viewBox = $viewBox, expected = ${expected.toList()}")
        val svgNode = SvgRootNode(
            parent = XmlRootNode(children = mutableSetOf()),
            children = mutableSetOf(),
            attributes = mutableMapOf(
                "viewBox" to viewBox,
            ),
        )
        val actual = svgNode.parseViewBox()
        assertContentEquals(expected, actual)
    }
}

Outputs the following test names:

  • testViewBoxWithSpacesAsSeparators
  • testViewBoxWithSpacesAsSeparators_1_to
  • testViewBoxWithSpacesAsSeparators_2_to
  • testViewBoxWithSpacesAsSeparators_3_to

In contrast, another test case:

@Burst
class NumbersTest {
    @BeforeTest
    fun setup() {
        println("before running test")
    }

    @Test
    fun testSumIsEven(
        fistNumber: Int = burstValues(2, 4, 6),
        secondNumber: Int = burstValues(2, 4, 6),
    ) {
        assertEquals(0, (fistNumber + secondNumber) % 2)
    }
}

yields more descriptive output:

  • testSumIsEven
  • testSumIsEven_2_4
  • testSumIsEven_2_6
  • testSumIsEven_4_2
  • testSumIsEven_4_4
  • testSumIsEven_4_6
  • testSumIsEven_6_2
  • testSumIsEven_6_4
  • testSumIsEven_6_6

For the "set of parameter" option, it would be helpful if the output were formatted like this: testViewBoxWithSpacesAsSeparators_0_0_120_120_to_0f_0f_120f_120f.

Alternatively, another format could be: testViewBoxWithSpacesAsSeparators_[0_0_120_120]_to_[0f 0f 120f 120f], however, I believe the last option may not be feasible because using [ and ] as characters are not allowed in test names.

I would appreciate any guidance on how to make the test name outputs more informative when using Burst.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant