Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
Tests to YEAR TO MONTH type and fix for the comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed Jul 8, 2016
1 parent c422cfa commit c350c1a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/deveeldb-nunit/Deveel.Data.Sql.Objects/SqlIntervalTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,38 @@ public class SqlIntervalTests {

Assert.AreEqual(1, result);
}

[TestCase(22, 1)]
[Category("Year To Month")]
[Category("Conversion")]
public void YearToMonthFromInteger(int months, int expectedYears) {
var value = new SqlYearToMonth(months);

Assert.IsNotNull(value);
Assert.IsFalse(value.IsNull);

Assert.AreEqual(expectedYears, (int) value.TotalYears);
}

[Test]
[Category("Year To Month")]
public void CompareYearToMonths() {
var value1 = new SqlYearToMonth(22);
var value2 = new SqlYearToMonth(1, 2);

var result = value1.CompareTo(value2);
Assert.AreEqual(1, result);
}

[Test]
[Category("Year To Month")]
public void CompareYearToMonthToNull() {
var value1 = new SqlYearToMonth(22);
var value2 = SqlYearToMonth.Null;

var result = value1.CompareTo(value2);

Assert.AreEqual(1, result);
}
}
}
4 changes: 2 additions & 2 deletions src/deveeldb/Deveel.Data.Sql.Objects/SqlYearToMonth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ private SqlYearToMonth(bool isNull)
if (other.IsNull && IsNull)
return 0;
if (IsNull && !other.IsNull)
return 1;
if (!IsNull && other.IsNull)
return -1;
if (!IsNull && other.IsNull)
return 1;

return months.Value.CompareTo(other.months.Value);
}
Expand Down

0 comments on commit c350c1a

Please sign in to comment.