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

Add support for arrays #6

Open
dotnetwise opened this issue Jul 14, 2014 · 4 comments
Open

Add support for arrays #6

dotnetwise opened this issue Jul 14, 2014 · 4 comments

Comments

@dotnetwise
Copy link

So that the following would be possible too:

QUnit
    .cases([
        [2, 3, 5],
        [1, 2, 3],
        [-1, 0, -1],
    ])
    .test("Sum test", function(a, b, expectedSum) {
        var actualSum = sum(a, b);
        equal(actualSum, expectedSum);
    });
@AStepaniuk
Copy link
Owner

Yeah, the idea sounds good.

It requires also to think how should look rules for test cases generation feature.
What if we mix array + array, array + object?
Should probaby test cases generation be forbidden when the array is a source ar a mixin?

@dotnetwise
Copy link
Author

It doesen't really matter.
It's quite simple I guess.
If the item is an array, then pass it as arguments
If the item is an object then pass it as first argument named params.

I don't think people will mix them up, and even if they do, that would make sense for them to check arguments.length > 1 to see what kind of test case scenario they are upon.

When multiplying values via combinatorial([...]) or .sequential You could do the same as if it would be an object e.g.

QUnit
    .cases([
        { a : 1 },
        [1, 2, 3],
    ])
    .combinatorial([
        ["one", "two", "three"],
        null,
        { b : "null" }
    ])

Produces test cases:

[
    { title : "case1 mix1", a : 1, array2: ["one", "two", "three"] },
    { title : "case1 mix2", a : 1 },
    { title : "case1 mix3", a : 1, b: "null" },
    { title : "case2 mix1", array1 : [1,2,3], array2: ["one", "two", "three"] },
    { title : "case2 mix2", array1 : [1,2,3] },
    { title : "case2 mix3", array1 : [1,2,3], b: "null" },
]

@AStepaniuk
Copy link
Owner

Ok, that sounds reasonable.
Let's say to user: 'you know what you are doing when trying to mix arrays and objects'.

Just instead of properties array1, array2, etc. I think we'd better had an array of arrays.
I.e.

[
    { title : "case1 mix1", a : 1, arrays : [undefined, ["one", "two", "three"]] },
    { title : "case1 mix2", a : 1 },
    { title : "case1 mix3", a : 1, b: "null" },
    { title : "case2 mix1", arrays : [[1,2,3], ["one", "two", "three"]] },
    { title : "case2 mix2", arrays : [[1,2,3]] },
    { title : "case2 mix3", arrays : [[1,2,3]], b: "null" },
]

or something similar...

@dotnetwise
Copy link
Author

Makes sense.

I think mixing arrays with objects is not the most util part, however, mixing arrays altogether is where the power comes along.

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

No branches or pull requests

2 participants