Skip to content

test(sum): add more sum tests#1071

Open
giard-alexandre wants to merge 1 commit intoreactivemarbles:mainfrom
giard-alexandre:tests/sum
Open

test(sum): add more sum tests#1071
giard-alexandre wants to merge 1 commit intoreactivemarbles:mainfrom
giard-alexandre:tests/sum

Conversation

@giard-alexandre
Copy link

This should address the first 3 bullet points in #1031 (comment)

Copy link
Collaborator

@JakenVeina JakenVeina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid, overall. A few nitpicks, and a few suggested new tests/test cases.

}

[Fact]
public void NoItemsAdded_NoSumEmitted()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reflects what the current behavior is? If so, it's one of the things that should be considered for a change. The most compelling argument, I think, is that Enumerable.Sum() emits 0 on an empty source, rather than, say, throwing an exception, so that's probably what consumers are going to expect, intuitively.

Not asking for a change, if this is the current behavior, that's what the test should reflect. Just musing about something to consider in the next phase.

}

[Fact]
public void NoItemsAdded_NoSumEmitted()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Me, I'd probably use SourceIsEmpty to describe the scenario here. It's slightly clearer about what's really being tested.

}

[Fact]
public void AllItemsRemoved_SumReturnsToZero()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this definitely confirms that we should be emitting 0 upon subscription to an empty source.

[InlineData(0, 50)]
[InlineData(1, 40)]
[InlineData(2, 30)]
public void ItemIsRemoved_SumDecreases(int removalIndex, int expectedSum)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably SumReflectsRemoval works better, and matches what you've used elsewhere. This actually highlights that you should probably add test cases for negative values, for completeness' sake.


[Fact]
public void AddedItemsContributeToSumDouble()
public class ListSource
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely split these into separate files. To match other operators where we've got multiple overloads, I'd do SumFixture.ForCache.cs and SumFixture.ForList.cs. Check out (if I recall correctly) ToObservableChangeSetFixture.

}

[Fact]
public void SourceCompletesAfterEmitting_CompletionPropagates()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add equivalent tests for SourceCompletesImmediately and SourceFailsImmediately.

Quite often, these scenarios need a little bit of custom logic, to ensure correct behavior, especially for operators that emit an initial value, or that should always emit a value when the source emits one.

In the case of Sum(), a source can exist that emits an initial changeset, and then a completion, because no new item changes are allowed, and these would both occur immediately upon subscription. We'd want to make sure that .Sum() also emits an initial sum value, for those items, and then a completion, both immediately upon subscription.

}

[Fact]
public void ItemsAreAdded_SumIsCorrect_ForInt()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're targeting specific numeric types, we should probably add some test cases for .MaxValue and .MinValue to guarantee no overflows occurring where there shouldn't be. Maybe as new test cases to these existing tests, maybe as dedicated test methods.

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

Successfully merging this pull request may close these issues.

2 participants