Skip to content
Merged
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 tests for logical (bool) comparison operators
  • Loading branch information
christabella committed Jan 12, 2021
commit bcbace35ba5ad003c8eb6336be81e4302397efdf
90 changes: 89 additions & 1 deletion src/embed_tests/TestOperator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,58 @@ public OperableObject(int num)
return new OperableObject(a.Num ^ b);
}

public static bool operator <=(int a, OperableObject b)
{
return (a <= b.Num);
}
public static bool operator <=(OperableObject a, OperableObject b)
{
return (a.Num <= b.Num);
}
public static bool operator <=(OperableObject a, int b)
{
return (a.Num <= b);
}

public static bool operator >=(int a, OperableObject b)
{
return (a >= b.Num);
}
public static bool operator >=(OperableObject a, OperableObject b)
{
return (a.Num >= b.Num);
}
public static bool operator >=(OperableObject a, int b)
{
return (a.Num >= b);
}

public static bool operator<(int a, OperableObject b)
{
return (a < b.Num);
}
public static bool operator<(OperableObject a, OperableObject b)
{
return (a.Num < b.Num);
}
public static bool operator<(OperableObject a, int b)
{
return (a.Num < b);
}

public static bool operator>(int a, OperableObject b)
{
return (a > b.Num);
}
public static bool operator>(OperableObject a, OperableObject b)
{
return (a.Num > b.Num);
}
public static bool operator >(OperableObject a, int b)
{
return (a.Num > b);
}

public static OperableObject operator <<(OperableObject a, int offset)
{
return new OperableObject(a.Num << offset);
Expand All @@ -161,7 +213,7 @@ public OperableObject(int num)
}

[Test]
public void OperatorOverloads()
public void SymmetricalOperatorOverloads()
{
string name = string.Format("{0}.{1}",
typeof(OperableObject).DeclaringType.Name,
Expand Down Expand Up @@ -206,6 +258,18 @@ public void OperatorOverloads()

c = a ^ b
assert c.Num == a.Num ^ b.Num

c = a <= b
assert c == (a.Num <= b.Num)

c = a >= b
assert c == (a.Num >= b.Num)

c = a < b
assert c == (a.Num < b.Num)

c = a > b
assert c == (a.Num > b.Num)
");
}

Expand Down Expand Up @@ -263,6 +327,18 @@ public void ForwardOperatorOverloads()

c = a ^ b
assert c.Num == a.Num ^ b

c = a <= b
assert c == (a.Num <= b)

c = a >= b
assert c == (a.Num >= b)

c = a < b
assert c == (a.Num < b)

c = a > b
assert c == (a.Num > b)
");
}

Expand Down Expand Up @@ -304,6 +380,18 @@ public void ReverseOperatorOverloads()

c = a ^ b
assert c.Num == a ^ b.Num

c = a <= b
assert c == (a <= b.Num)

c = a >= b
assert c == (a >= b.Num)

c = a < b
assert c == (a < b.Num)

c = a > b
assert c == (a > b.Num)
");

}
Expand Down