VibeCoding and testing to BDD to understand the output

So the AI has written all tests for the solution. But now the problem was reading all those tests.
For example for this code

 public static class ArrayFilters
 {
     // Checks if the argument is included in the comparison array
     public static bool IsIncludedIn<T>(T arg, T[] comparisonArray)
     {
         return comparisonArray != null && comparisonArray.Contains(arg);
     }

     // Checks if the argument is NOT included in the comparison array
     public static bool IsNotIncludedIn<T>(T arg, T[] comparisonArray)
     {
         return comparisonArray == null || !comparisonArray.Contains(arg);
     }

     // Used on arrays of arrays (2D arrays). Returns true if all elements in the nested array pass the test
     public static bool EveryElement<T>(T[] array, Func<T, bool> condition)
     {
         return array != null && array.All(condition);
     }
 }

those are the tests :

public class ArrayFiltersTests
{
    [Fact]
    public void IsIncludedIn_ReturnsTrueIfIncluded()
    {
        int[] arr = { 1, 2, 3 };
        Assert.True(ArrayFilters.IsIncludedIn(2, arr));
        Assert.False(ArrayFilters.IsIncludedIn(4, arr));
    }

    [Fact]
    public void IsNotIncludedIn_ReturnsTrueIfNotIncluded()
    {
        int[] arr = { 1, 2, 3 };
        Assert.True(ArrayFilters.IsNotIncludedIn(4, arr));
        Assert.False(ArrayFilters.IsNotIncludedIn(2, arr));
    }

    [Fact]
    public void EveryElement_ReturnsTrueIfAllPassCondition()
    {
        int[] arr = { 2, 4, 6 };
        Assert.True(ArrayFilters.EveryElement(arr, x => x % 2 == 0));
        Assert.False(ArrayFilters.EveryElement(arr, x => x > 4));
    }
}

It is not so easy to read the test . So – let’s put the AI to work to change in a BDD style – see Whole discussion
Now the test looks like this

    [FeatureDescription(
        "ArrayFilters: BDD scenarios for array filter functions.")]
    public class ArrayFiltersFeature : FeatureFixture
    {
        private int[] arr = Array.Empty<int>();
        private bool result;

        private void GivenArray(params int[] values) => arr = values;
        private void WhenIsIncludedIn(int value) => result = FpFilters.ArrayFilters.ArrayFilters.IsIncludedIn(value, arr);
        private void WhenIsNotIncludedIn(int value) => result = FpFilters.ArrayFilters.ArrayFilters.IsNotIncludedIn(value, arr);
        private void WhenEveryElement(Func<int, bool> condition) => result = FpFilters.ArrayFilters.ArrayFilters.EveryElement(arr, condition);
        private void ThenResultShouldBeTrue() => Xunit.Assert.True(result);
        private void ThenResultShouldBeFalse() => Xunit.Assert.False(result);

        [Scenario]
        public void Should_check_if_value_is_included_in_array()
        {
            Runner.RunScenario(
                _ => GivenArray(1, 2, 3),
                _ => WhenIsIncludedIn(2),
                _ => ThenResultShouldBeTrue(),
                _ => WhenIsIncludedIn(4),
                _ => ThenResultShouldBeFalse()
            );
        }

        [Scenario]
        public void Should_check_if_value_is_not_included_in_array()
        {
            Runner.RunScenario(
                _ => GivenArray(1, 2, 3),
                _ => WhenIsNotIncludedIn(4),
                _ => ThenResultShouldBeTrue(),
                _ => WhenIsNotIncludedIn(2),
                _ => ThenResultShouldBeFalse()
            );
        }

        [Scenario]
        public void Should_check_if_every_element_passes_condition()
        {
            Runner.RunScenario(
                _ => GivenArray(2, 4, 6),
                _ => WhenEveryElement(x => x % 2 == 0),
                _ => ThenResultShouldBeTrue(),
                _ => WhenEveryElement(x => x > 4),
                _ => ThenResultShouldBeFalse()
            );
        }
    }

But , more important, this is the output

SCENARIO: Should check if value is included in array
  STEP 1/5: GivenArray [values: "1, 2, 3"]...
  STEP 1/5: GivenArray [values: "1, 2, 3"] (Passed after 3ms)
  STEP 2/5: WhenIsIncludedIn [value: "2"]...
  STEP 2/5: WhenIsIncludedIn [value: "2"] (Passed after <1ms)
  STEP 3/5: ThenResultShouldBeTrue...
  STEP 3/5: ThenResultShouldBeTrue (Passed after <1ms)
  STEP 4/5: WhenIsIncludedIn [value: "4"]...
  STEP 4/5: WhenIsIncludedIn [value: "4"] (Passed after <1ms)
  STEP 5/5: ThenResultShouldBeFalse...
  STEP 5/5: ThenResultShouldBeFalse (Passed after <1ms)
  SCENARIO RESULT: Passed after 22ms
SCENARIO: Should check if value is not included in array
  STEP 1/5: GivenArray [values: "1, 2, 3"]...
  STEP 1/5: GivenArray [values: "1, 2, 3"] (Passed after <1ms)
  STEP 2/5: WhenIsNotIncludedIn [value: "4"]...
  STEP 2/5: WhenIsNotIncludedIn [value: "4"] (Passed after <1ms)
  STEP 3/5: ThenResultShouldBeTrue...
  STEP 3/5: ThenResultShouldBeTrue (Passed after <1ms)
  STEP 4/5: WhenIsNotIncludedIn [value: "2"]...
  STEP 4/5: WhenIsNotIncludedIn [value: "2"] (Passed after <1ms)
  STEP 5/5: ThenResultShouldBeFalse...
  STEP 5/5: ThenResultShouldBeFalse (Passed after <1ms)
  SCENARIO RESULT: Passed after 2ms
SCENARIO: Should check if every element passes condition
  STEP 1/5: GivenArray [values: "2, 4, 6"]...
  STEP 1/5: GivenArray [values: "2, 4, 6"] (Passed after <1ms)
  STEP 2/5: WhenEveryElement [condition: "System.Func`2[System.Int32,System.Boolean]"]...
  STEP 2/5: WhenEveryElement [condition: "System.Func`2[System.Int32,System.Boolean]"] (Passed after <1ms)
  STEP 3/5: ThenResultShouldBeTrue...
  STEP 3/5: ThenResultShouldBeTrue (Passed after <1ms)
  STEP 4/5: WhenEveryElement [condition: "System.Func`2[System.Int32,System.Boolean]"]...
  STEP 4/5: WhenEveryElement [condition: "System.Func`2[System.Int32,System.Boolean]"] (Passed after <1ms)
  STEP 5/5: ThenResultShouldBeFalse...
  STEP 5/5: ThenResultShouldBeFalse (Passed after <1ms)
  SCENARIO RESULT: Passed after 3ms
FEATURE FINISHED: ArrayFiltersFeature

The result is a comprehensive, understandable test suite that makes it easy to spot issues and verify correctness.
I can read the output and see if something is wrong.

Commit : https://github.com/ignatandrei/Filters/commit/1d35d2eb2ee5a4e78346ba95f163e0d67e221fbe

Discussion

Human Text:

Please convert the Array Filters test in LightBDD ( or other Unit test framework that supports output as BDD )

AI Text:

If you want to convert other test groups to BDD or need further customization, let me know!

Human Text:

Please modify all tests to support BDD in this manner

AI Text:

I will continue converting the remaining test groups to LightBDD BDD scenarios, following the same approach for each. Let me know if you want to prioritize any specific group or proceed with all.

Human Text:

Please modify all tests to support BDD in this manner

AI Text

Both failures are due to the handling of the value 0—the test expects 0 to be considered “null or default” in one scenario and “not null or default” in the other, but the actual result is the opposite. This suggests a logic or test expectation mismatch for how 0 should be treated by your IsNullOrDefault and IsNotNullOrDefault filters.
Would you like to adjust the filter logic, or update the test expectations for the value 0?

Human Text:

adjust the filter logic to support just classes

AI Text

To fully resolve the issue, you should update the test expectations in MiscFiltersBddTests.cs so that value types like 0 are not treated as “null or default”. Would you like me to update the BDD tests accordingly?

Human Text:

Yes

AI Text:

Your C# translation of 130+ functional filters, grouped and tested in BDD style, is now complete and fully validated. If you want to address the remaining warnings or need further enhancements, let me know!


Posted

in

, , , ,

by

Tags: