|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Improbable.Gdk.Core; |
| 4 | +using Improbable.Gdk.QueryBasedInterest; |
| 5 | +using NUnit.Framework; |
| 6 | + |
| 7 | +namespace Improbable.Gdk.EditmodeTests.Utility |
| 8 | +{ |
| 9 | + [TestFixture] |
| 10 | + public class ConstraintTests |
| 11 | + { |
| 12 | + private const double Distance = 10; |
| 13 | + |
| 14 | + private static Constraint BasicConstraint => Constraint.Component<Position.Component>(); |
| 15 | + |
| 16 | + [Test] |
| 17 | + public void All_constraint_throws_if_enumerable_empty() |
| 18 | + { |
| 19 | + Assert.Throws<ArgumentException>(() => Constraint.All(new List<Constraint>())); |
| 20 | + } |
| 21 | + |
| 22 | + [Test] |
| 23 | + public void Any_constraint_throws_if_enumerable_empty() |
| 24 | + { |
| 25 | + Assert.Throws<ArgumentException>(() => Constraint.Any(new List<Constraint>())); |
| 26 | + } |
| 27 | + |
| 28 | + [Test] |
| 29 | + public void All_constraint_param_sets_OrConstraint_to_empty_list() |
| 30 | + { |
| 31 | + var constraint = Constraint.All(BasicConstraint); |
| 32 | + Assert.AreEqual(constraint.AsQueryConstraint().AndConstraint.Count, 1); |
| 33 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 34 | + } |
| 35 | + |
| 36 | + [Test] |
| 37 | + public void All_constraint_params_sets_OrConstraint_to_empty_list() |
| 38 | + { |
| 39 | + var constraint = Constraint.All(BasicConstraint, BasicConstraint, BasicConstraint); |
| 40 | + Assert.AreEqual(constraint.AsQueryConstraint().AndConstraint.Count, 3); |
| 41 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 42 | + } |
| 43 | + |
| 44 | + [Test] |
| 45 | + public void All_constraint_enumerable_sets_OrConstraint_to_empty_list() |
| 46 | + { |
| 47 | + var constraint = Constraint.All(new List<Constraint> { BasicConstraint }); |
| 48 | + Assert.AreEqual(constraint.AsQueryConstraint().AndConstraint.Count, 1); |
| 49 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 50 | + } |
| 51 | + |
| 52 | + [Test] |
| 53 | + public void Any_constraint_param_sets_AndConstraint_to_empty_list() |
| 54 | + { |
| 55 | + var constraint = Constraint.Any(BasicConstraint); |
| 56 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 57 | + Assert.AreEqual(constraint.AsQueryConstraint().OrConstraint.Count, 1); |
| 58 | + } |
| 59 | + |
| 60 | + [Test] |
| 61 | + public void Any_constraint_params_sets_AndConstraint_to_empty_list() |
| 62 | + { |
| 63 | + var constraint = Constraint.Any(BasicConstraint, BasicConstraint, BasicConstraint); |
| 64 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 65 | + Assert.AreEqual(constraint.AsQueryConstraint().OrConstraint.Count, 3); |
| 66 | + } |
| 67 | + |
| 68 | + [Test] |
| 69 | + public void Any_constraint_enumerable_sets_AndConstraint_to_empty_list() |
| 70 | + { |
| 71 | + var constraint = Constraint.Any(new List<Constraint> { BasicConstraint }); |
| 72 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 73 | + Assert.AreEqual(constraint.AsQueryConstraint().OrConstraint.Count, 1); |
| 74 | + } |
| 75 | + |
| 76 | + [Test] |
| 77 | + public void Sphere_constraint_sets_AndOr_constraints_to_empty_list() |
| 78 | + { |
| 79 | + var constraint = Constraint.Sphere(Distance, Coordinates.Zero); |
| 80 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 81 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 82 | + } |
| 83 | + |
| 84 | + [Test] |
| 85 | + public void Sphere_constraint_xyz_sets_AndOr_constraints_to_empty_list() |
| 86 | + { |
| 87 | + var constraint = Constraint.Sphere(Distance, 0, 0, 0); |
| 88 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 89 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 90 | + } |
| 91 | + |
| 92 | + [Test] |
| 93 | + public void Cylinder_constraint_sets_AndOr_constraints_to_empty_list() |
| 94 | + { |
| 95 | + var constraint = Constraint.Cylinder(Distance, Coordinates.Zero); |
| 96 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 97 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 98 | + } |
| 99 | + |
| 100 | + [Test] |
| 101 | + public void Cylinder_constraint_xyz_sets_AndOr_constraints_to_empty_list() |
| 102 | + { |
| 103 | + var constraint = Constraint.Cylinder(Distance, 0, 0, 0); |
| 104 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 105 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 106 | + } |
| 107 | + |
| 108 | + [Test] |
| 109 | + public void Box_constraint_sets_AndOr_constraints_to_empty_list() |
| 110 | + { |
| 111 | + var constraint = Constraint.Box(Distance, Distance, Distance, Coordinates.Zero); |
| 112 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 113 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 114 | + } |
| 115 | + |
| 116 | + [Test] |
| 117 | + public void Box_constraint__xyz_sets_AndOr_constraints_to_empty_list() |
| 118 | + { |
| 119 | + var constraint = Constraint.Box(Distance, Distance, Distance, 0, 0, 0); |
| 120 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 121 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 122 | + } |
| 123 | + |
| 124 | + [Test] |
| 125 | + public void RelativeSphere_constraint_sets_AndOr_constraints_to_empty_list() |
| 126 | + { |
| 127 | + var constraint = Constraint.RelativeSphere(Distance); |
| 128 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 129 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 130 | + } |
| 131 | + |
| 132 | + [Test] |
| 133 | + public void RelativeCylinder_constraint_sets_AndOr_constraints_to_empty_list() |
| 134 | + { |
| 135 | + var constraint = Constraint.RelativeCylinder(Distance); |
| 136 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 137 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 138 | + } |
| 139 | + |
| 140 | + [Test] |
| 141 | + public void RelativeBox_constraint_sets_AndOr_constraints_to_empty_list() |
| 142 | + { |
| 143 | + var constraint = Constraint.RelativeBox(Distance, Distance, Distance); |
| 144 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 145 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 146 | + } |
| 147 | + |
| 148 | + [Test] |
| 149 | + public void EntityId_constraint_sets_AndOr_constraints_to_empty_list() |
| 150 | + { |
| 151 | + var constraint = Constraint.EntityId(new EntityId(10)); |
| 152 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 153 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 154 | + } |
| 155 | + |
| 156 | + [Test] |
| 157 | + public void Component_constraint_sets_AndOr_constraints_to_empty_list() |
| 158 | + { |
| 159 | + var constraint = Constraint.Component(Position.ComponentId); |
| 160 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 161 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 162 | + } |
| 163 | + |
| 164 | + [Test] |
| 165 | + public void Component_T_constraint_sets_AndOr_constraints_to_empty_list() |
| 166 | + { |
| 167 | + var constraint = Constraint.Component<Position.Component>(); |
| 168 | + Assert.AreEqual(0, constraint.AsQueryConstraint().AndConstraint.Count); |
| 169 | + Assert.AreEqual(0, constraint.AsQueryConstraint().OrConstraint.Count); |
| 170 | + } |
| 171 | + } |
| 172 | +} |
0 commit comments