Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add IsZero() and IsNotZero() methods for int assertions
Co-authored-by: thomhurst <[email protected]>
  • Loading branch information
Copilot and thomhurst committed Nov 1, 2025
commit e1c45447d8bef49659e87812e9461008a6b51ed5
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Library.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net8.0;net9.0;net10.0</TargetFrameworks>

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

Expand Down
75 changes: 75 additions & 0 deletions TUnit.Assertions.Tests/IntAssertionTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using TUnit.Assertions.Extensions;

namespace TUnit.Assertions.Tests;

public class IntAssertionTests
{
[Test]
public async Task Test_Int_IsZero()
{
var value = 0;
await Assert.That(value).IsZero();
}

[Test]
public async Task Test_Int_IsZero_Literal()
{
await Assert.That(0).IsZero();
}

[Test]
public async Task Test_Int_IsNotZero_Positive()
{
var value = 1;
await Assert.That(value).IsNotZero();
}

[Test]
public async Task Test_Int_IsNotZero_Negative()
{
var value = -1;
await Assert.That(value).IsNotZero();
}

[Test]
public async Task Test_Int_IsNotZero_Large()
{
var value = 1000000;
await Assert.That(value).IsNotZero();
}

[Test]
public async Task Test_Int_IsEven_Zero()
{
var value = 0;
await Assert.That(value).IsEven();
}

[Test]
public async Task Test_Int_IsEven_Positive()
{
var value = 2;
await Assert.That(value).IsEven();
}

[Test]
public async Task Test_Int_IsEven_Negative()
{
var value = -4;
await Assert.That(value).IsEven();
}

[Test]
public async Task Test_Int_IsOdd_Positive()
{
var value = 3;
await Assert.That(value).IsOdd();
}

[Test]
public async Task Test_Int_IsOdd_Negative()
{
var value = -5;
await Assert.That(value).IsOdd();
}
}
12 changes: 12 additions & 0 deletions TUnit.Assertions/IntAssertions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ namespace TUnit.Assertions;

public static partial class IntAssertions
{
[GenerateAssertion(ExpectationMessage = "to be zero")]
public static bool IsZero(this int value)
{
return value == 0;
}

[GenerateAssertion(ExpectationMessage = "to not be zero")]
public static bool IsNotZero(this int value)
{
return value != 0;
}

[GenerateAssertion]
public static bool IsEven(this int value)
{
Expand Down
2 changes: 1 addition & 1 deletion TestProject.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />

<PropertyGroup>
<TargetFrameworks>net472;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>

<OutputType>Exe</OutputType>

Expand Down
Loading