13using System.Diagnostics;
14using System.Collections.Generic;
16public static class AssertHelper {
18 [Conditional(
"UNITY_EDITOR")]
19 public static void AssertRuntimeOnly(
string message =
null) {
20 message = message ??
"Assert failed because game was not in Play Mode.";
21 Assert.IsTrue(Application.isPlaying, message);
24 [Conditional(
"UNITY_EDITOR")]
25 public static void AssertEditorOnly(
string message =
null) {
26 message = message ??
"Assert failed because game was in Play Mode.";
27 Assert.IsFalse(Application.isPlaying, message);
30 [Conditional(
"UNITY_ASSERTIONS")]
31 public static void Implies(
bool condition,
bool result,
string message =
"") {
33 Assert.IsTrue(result, message);
37 [Conditional(
"UNITY_ASSERTIONS")]
38 public static void Implies(
bool condition, Func<bool> result,
string message =
"") {
40 Implies(condition, result(), message);
44 [Conditional(
"UNITY_ASSERTIONS")]
45 public static void Implies(
string conditionName,
bool condition,
string resultName,
bool result) {
46 Implies(condition, result,
"When " + conditionName +
" is true, " + resultName +
" must always be true.");
49 [Conditional(
"UNITY_ASSERTIONS")]
50 public static void Implies(
string conditionName,
bool condition,
string resultName, Func<bool> result) {
52 Implies(conditionName, condition, resultName, result());
56 [Conditional(
"UNITY_ASSERTIONS")]
57 public static void Contains<T>(T value, IEnumerable<T> collection,
string message =
"") {
58 if (!collection.Contains(value)) {
59 string result =
"The value " + value +
" was not found in the collection [";
62 foreach (T v
in collection) {
68 result += v.ToString();
71 result +=
"]\n" + message;
72 Assert.IsTrue(
false, result);