This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git

commit 1cf794888dad6abf645b380e70d65f071aa91120
Author: Josh Tynjala <[email protected]>
AuthorDate: Mon Dec 19 12:40:42 2022 -0800

    RoyaleUnit: assertLessThan, assertGreaterThan, assertLessThanOrEqual, 
assertGreaterThanOrEqual
---
 .../main/royale/org/apache/royale/test/Assert.as   | 85 ++++++++++++++++++++++
 .../royale/test/asserts/assertGreaterThan.as       | 30 ++++++++
 .../test/asserts/assertGreaterThanOrEqual.as       | 30 ++++++++
 .../apache/royale/test/asserts/assertLessThan.as   | 30 ++++++++
 .../royale/test/asserts/assertLessThanOrEqual.as   | 30 ++++++++
 .../royale/org/apache/royale/test/bdd/IExpect.as   | 64 ++++++++++++++++
 .../royale/org/apache/royale/test/bdd/expect.as    | 72 ++++++++++++++++++
 .../src/test/royale/tests/AssertTests.as           | 72 ++++++++++++++++++
 .../src/test/royale/tests/ExpectBDDTests.as        | 72 ++++++++++++++++++
 9 files changed, 485 insertions(+)

diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as
index d10b92fc15..d5f9071df2 100644
--- 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/Assert.as
@@ -163,6 +163,46 @@ package org.apache.royale.test
                        failWithin(actual, minimum, maximum, message);
                }
 
+               /**
+                * Asserts that the provided value is less than another value.
+                * Equivalent to testing the value in an <code>if(value < 
other)</code>
+                * statement.
+                */
+               public static function assertLessThan(actual:Number, 
other:Number, message:String = null):void
+               {
+                       failGreaterThanOrEqual(actual, other, message);
+               }
+
+               /**
+                * Asserts that the provided value is greater than another 
value.
+                * Equivalent to testing the value in an <code>if(value > 
other)</code>
+                * statement.
+                */
+               public static function assertGreaterThan(actual:Number, 
other:Number, message:String = null):void
+               {
+                       failLessThanOrEqual(actual, other, message);
+               }
+
+               /**
+                * Asserts that the provided value is less or equal to than 
another
+                * value. Equivalent to testing the value in an
+                * <code>if(value <= other)</code> statement.
+                */
+               public static function assertLessThanOrEqual(actual:Number, 
other:Number, message:String = null):void
+               {
+                       failGreaterThan(actual, other, message);
+               }
+
+               /**
+                * Asserts that the provided value is greater than or equal to 
another
+                * value. Equivalent to testing the value in an
+                * <code>if(value >= other)</code> statement.
+                */
+               public static function assertGreaterThanOrEqual(actual:Number, 
other:Number, message:String = null):void
+               {
+                       failLessThan(actual, other, message);
+               }
+
                /**
                 * Fails.
                 */
@@ -328,6 +368,51 @@ package org.apache.royale.test
                        }
                }
 
+               /**
+                * Fails if the provided value is less than another value.
+                */
+               public static function failLessThan(actual:Number, 
other:Number, message:String = null):void
+               {
+                       if (actual < other)
+                       {
+                               failWithUserMessage("expected greater than or 
equal to <" + other + "> but was <" + actual + ">", message);
+                       }
+               }
+
+               /**
+                * Fails if the provided value is greater than another value.
+                */
+               public static function failGreaterThan(actual:Number, 
other:Number, message:String = null):void
+               {
+                       if (actual > other)
+                       {
+                               failWithUserMessage("expected less than or 
equal to <" + other + "> but was <" + actual + ">", message);
+                       }
+               }
+
+               /**
+                * Fails if the provided value is less than or equal to another 
value.
+                */
+               public static function failLessThanOrEqual(actual:Number, 
other:Number, message:String = null):void
+               {
+                       if (actual <= other)
+                       {
+                               failWithUserMessage("expected greater than <" + 
other + "> but was <" + actual + ">", message);
+                       }
+               }
+
+               /**
+                * Fails if the provided value is greater than or equal to 
another
+                * value.
+                */
+               public static function failGreaterThanOrEqual(actual:Number, 
other:Number, message:String = null):void
+               {
+                       if (actual >= other)
+                       {
+                               failWithUserMessage("expected less than <" + 
other + "> but was <" + actual + ">", message);
+                       }
+               }
+
                /**
                 * @private
                 */
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThan.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThan.as
new file mode 100644
index 0000000000..fd2177ee1c
--- /dev/null
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThan.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.test.asserts
+{
+       import org.apache.royale.test.Assert;
+
+       /**
+        * Alias for org.apache.royale.test.Assert assertGreaterThan method
+        */
+       public function assertGreaterThan(actual:Number, other:Number, 
message:String = null):void
+       {
+               Assert.assertGreaterThan(actual, other, message);
+       }
+}
\ No newline at end of file
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThanOrEqual.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThanOrEqual.as
new file mode 100644
index 0000000000..527f6f3fc8
--- /dev/null
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertGreaterThanOrEqual.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.test.asserts
+{
+       import org.apache.royale.test.Assert;
+
+       /**
+        * Alias for org.apache.royale.test.Assert assertGreaterThanOrEqual 
method
+        */
+       public function assertGreaterThanOrEqual(actual:Number, other:Number, 
message:String = null):void
+       {
+               Assert.assertGreaterThanOrEqual(actual, other, message);
+       }
+}
\ No newline at end of file
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThan.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThan.as
new file mode 100644
index 0000000000..fca892f44b
--- /dev/null
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThan.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.test.asserts
+{
+       import org.apache.royale.test.Assert;
+
+       /**
+        * Alias for org.apache.royale.test.Assert assertLessThan method
+        */
+       public function assertLessThan(actual:Number, other:Number, 
message:String = null):void
+       {
+               Assert.assertLessThan(actual, other, message);
+       }
+}
\ No newline at end of file
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThanOrEqual.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThanOrEqual.as
new file mode 100644
index 0000000000..76ca73c857
--- /dev/null
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/asserts/assertLessThanOrEqual.as
@@ -0,0 +1,30 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.test.asserts
+{
+       import org.apache.royale.test.Assert;
+
+       /**
+        * Alias for org.apache.royale.test.Assert assertLessThanOrEqual method
+        */
+       public function assertLessThanOrEqual(actual:Number, other:Number, 
message:String = null):void
+       {
+               Assert.assertLessThanOrEqual(actual, other, message);
+       }
+}
\ No newline at end of file
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as
index 9d49aec9bf..342b113439 100644
--- 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/IExpect.as
@@ -65,6 +65,70 @@ package org.apache.royale.test.bdd
                 */
                function within(minimum:Number, maximum:Number, message:String 
= null):IExpect;
 
+               /**
+                * Asserts that the provided value is less than another value.
+                * Equivalent to testing the value in an <code>if(value < 
other)</code>
+                * statement.
+                * 
+                * @see Assert#assertLessThan
+                */
+               function lessThan(other:Number, message:String = null):IExpect;
+
+               /**
+                * Asserts that the provided value is less or equal to than 
another
+                * value. Equivalent to testing the value in an
+                * <code>if(value <= other)</code> statement.
+                * 
+                * @see Assert#assertLessThanOrEqual
+                */
+               function lessThanOrEqual(other:Number, message:String = 
null):IExpect;
+
+               /**
+                * Asserts that the provided value is greater than another 
value.
+                * Equivalent to testing the value in an <code>if(value > 
other)</code>
+                * statement.
+                * 
+                * @see Assert#assertGreaterThan
+                */
+               function greaterThan(other:Number, message:String = 
null):IExpect;
+
+               /**
+                * Asserts that the provided value is greater than or equal to 
another
+                * value. Equivalent to testing the value in an
+                * <code>if(value >= other)</code> statement.
+                * 
+                * @see Assert#assertGreaterThanOrEqual
+                */
+               function greaterThanOrEqual(other:Number, message:String = 
null):IExpect;
+
+               /**
+                * Alias for <code>lessThan()</code>.
+                * 
+                * @see #lessThan
+                */
+               function lt(other:Number, message:String = null):IExpect;
+
+               /**
+                * Alias for <code>greaterThan()</code>.
+                * 
+                * @see #greaterThan
+                */
+               function gt(other:Number, message:String = null):IExpect;
+
+               /**
+                * Alias for <code>lessThanOrEqual()</code>.
+                * 
+                * @see #lessThanOrEqual
+                */
+               function lte(other:Number, message:String = null):IExpect;
+
+               /**
+                * Alias for <code>greaterThanOrEqual()</code>.
+                * 
+                * @see #greaterThanOrEqual
+                */
+               function gte(other:Number, message:String = null):IExpect;
+
                /**
                 * Negates all assertions that follow in the chain.
                 */
diff --git 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as
 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as
index b21258f4ff..d2979e1962 100644
--- 
a/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as
+++ 
b/frameworks/projects/RoyaleUnit/src/main/royale/org/apache/royale/test/bdd/expect.as
@@ -89,6 +89,78 @@ class Expect implements IExpect
                return this;
        }
 
+       public function lessThan(other:Number, message:String = null):IExpect
+       {
+               if (_not)
+               {
+                       Assert.failLessThan(_value, other, message);
+               }
+               else
+               {
+                       Assert.assertLessThan(_value, other, message);
+               }
+               return this;
+       }
+
+       public function greaterThan(other:Number, message:String = null):IExpect
+       {
+               if (_not)
+               {
+                       Assert.failGreaterThan(_value, other, message);
+               }
+               else
+               {
+                       Assert.assertGreaterThan(_value, other, message);
+               }
+               return this;
+       }
+
+       public function lessThanOrEqual(other:Number, message:String = 
null):IExpect
+       {
+               if (_not)
+               {
+                       Assert.failLessThanOrEqual(_value, other, message);
+               }
+               else
+               {
+                       Assert.assertLessThanOrEqual(_value, other, message);
+               }
+               return this;
+       }
+
+       public function greaterThanOrEqual(other:Number, message:String = 
null):IExpect
+       {
+               if (_not)
+               {
+                       Assert.failGreaterThanOrEqual(_value, other, message);
+               }
+               else
+               {
+                       Assert.assertGreaterThanOrEqual(_value, other, message);
+               }
+               return this;
+       }
+
+       public function lt(other:Number, message:String = null):IExpect
+       {
+               return lessThan(other, message);
+       }
+
+       public function lte(other:Number, message:String = null):IExpect
+       {
+               return lessThanOrEqual(other, message);
+       }
+
+       public function gt(other:Number, message:String = null):IExpect
+       {
+               return greaterThan(other, message);
+       }
+
+       public function gte(other:Number, message:String = null):IExpect
+       {
+               return greaterThanOrEqual(other, message);
+       }
+
        public function get not():IExpect
        {
                _not = !_not;
diff --git 
a/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as 
b/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as
index 7c89441578..28cb3b2ceb 100644
--- a/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as
+++ b/frameworks/projects/RoyaleUnit/src/test/royale/tests/AssertTests.as
@@ -841,6 +841,78 @@ package tests
                        Assert.assertWithin(1.0001, -1, 1);
                }
 
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertLessThanMatch():void
+               {
+                       Assert.assertLessThan(0, 0);
+               }
+
+               [Test]
+               public function testAssertLessThanLess():void
+               {
+                       Assert.assertLessThan(-1, 0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertLessThanGreater():void
+               {
+                       Assert.assertLessThan(1, 0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertGreaterThanMatch():void
+               {
+                       Assert.assertGreaterThan(0, 0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertGreaterThanLess():void
+               {
+                       Assert.assertGreaterThan(-1, 0);
+               }
+
+               [Test]
+               public function testAssertGreaterThanGreater():void
+               {
+                       Assert.assertGreaterThan(1, 0);
+               }
+
+               [Test]
+               public function testAssertLessThanOrEqualMatch():void
+               {
+                       Assert.assertLessThanOrEqual(0, 0);
+               }
+
+               [Test]
+               public function testAssertLessThanOrEqualLess():void
+               {
+                       Assert.assertLessThanOrEqual(-1, 0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertLessThanOrEqualGreater():void
+               {
+                       Assert.assertLessThanOrEqual(1, 0);
+               }
+
+               [Test]
+               public function testAssertGreaterThanOrEqualMatch():void
+               {
+                       Assert.assertGreaterThanOrEqual(0, 0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testAssertGreaterThanOrEqualLess():void
+               {
+                       Assert.assertGreaterThanOrEqual(-1, 0);
+               }
+
+               [Test]
+               public function testAssertGreaterThanOrEqualGreater():void
+               {
+                       Assert.assertGreaterThanOrEqual(1, 0);
+               }
+
                [Test(expected="org.apache.royale.test.AssertionError")]
                public function testFail():void
                {
diff --git 
a/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as 
b/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as
index 461741bd11..eac3e66c88 100644
--- a/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as
+++ b/frameworks/projects/RoyaleUnit/src/test/royale/tests/ExpectBDDTests.as
@@ -1620,5 +1620,77 @@ package tests
                {
                        expect(-1.0001).is.within(-1, 1);
                }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectLessThanMatch():void
+               {
+                       expect(0).lessThan(0);
+               }
+
+               [Test]
+               public function testExpectLessThanLess():void
+               {
+                       expect(-1).lessThan(0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectLessThanGreater():void
+               {
+                       expect(1).lessThan(0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectGreaterThanMatch():void
+               {
+                       expect(0).greaterThan(0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectGreaterThanLess():void
+               {
+                       expect(-1).greaterThan(0);
+               }
+
+               [Test]
+               public function testExpectGreaterThanGreater():void
+               {
+                       expect(1).greaterThan(0);
+               }
+
+               [Test]
+               public function testExpectLessThanOrEqualMatch():void
+               {
+                       expect(0).lessThanOrEqual(0);
+               }
+
+               [Test]
+               public function testExpectLessThanOrEqualLess():void
+               {
+                       expect(-1).lessThanOrEqual(0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectLessThanOrEqualGreater():void
+               {
+                       expect(1).lessThanOrEqual(0);
+               }
+
+               [Test]
+               public function testExpectGreaterThanOrEqualMatch():void
+               {
+                       expect(0).greaterThanOrEqual(0);
+               }
+
+               [Test(expected="org.apache.royale.test.AssertionError")]
+               public function testExpectGreaterThanOrEqualLess():void
+               {
+                       expect(-1).greaterThanOrEqual(0);
+               }
+
+               [Test]
+               public function testExpectGreaterThanOrEqualGreater():void
+               {
+                       expect(1).greaterThanOrEqual(0);
+               }
        }
 }
\ No newline at end of file

Reply via email to