[Argil-svn] SF.net SVN: argil: [512] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-04-01 04:35:55
|
Revision: 512
http://argil.svn.sourceforge.net/argil/?rev=512&view=rev
Author: tswicegood
Date: 2007-03-31 21:35:56 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
Add in the first pass at a Length Specification object
Added Paths:
-----------
branches/experimental/src/Argil/Specification/
branches/experimental/src/Argil/Specification/Length.php
branches/experimental/tests/Argil/Specification/
branches/experimental/tests/Argil/Specification/LengthTest.php
Added: branches/experimental/src/Argil/Specification/Length.php
===================================================================
--- branches/experimental/src/Argil/Specification/Length.php (rev 0)
+++ branches/experimental/src/Argil/Specification/Length.php 2007-04-01 04:35:56 UTC (rev 512)
@@ -0,0 +1,34 @@
+<?php
+
+class Argil_Specification_Length
+{
+ private
+ $_comparison,
+ $_length,
+ $_value;
+
+ public function __construct($value, $length, $comparison = '==') {
+ $this->_value = $value;
+ $this->_length = $length;
+ $this->_comparison = $comparison;
+ }
+
+ public function valid() {
+ $actualLength = strlen($this->_value);
+ switch ($this->_comparison) {
+ case '==' :
+ return $actualLength == $this->_length;
+ case '<=' :
+ return $actualLength <= $this->_length;
+ case '>=' :
+ return $actualLength >= $this->_length;
+ case '>' :
+ return $actualLength > $this->_length;
+ case '<' :
+ return $actualLength < $this->_length;
+ case '<>' :
+ case '!=' :
+ return $actualLength != $this->_length;
+ }
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Specification/LengthTest.php
===================================================================
--- branches/experimental/tests/Argil/Specification/LengthTest.php (rev 0)
+++ branches/experimental/tests/Argil/Specification/LengthTest.php 2007-04-01 04:35:56 UTC (rev 512)
@@ -0,0 +1,68 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Specification/Length.php';
+
+class Argil_Specification_LengthTest extends UnitTestCase
+{
+ public function testAllowsLengthEquals() {
+ $spec = new Argil_Specification_Length('12345', 5);
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5);
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthLesserThanOrEquals() {
+ $spec = new Argil_Specification_Length('12345', 5, '<=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 5, '<=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5, '<=');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthGreaterThanOrEquals() {
+ $spec = new Argil_Specification_Length('12345', 4, '>=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 4, '>=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123', 4, '>=');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthGreaterThan() {
+ $spec = new Argil_Specification_Length('12345', 4, '>');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('1234', 4, '>');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsLengthLesserThan() {
+ $spec = new Argil_Specification_Length('12345', 6, '<');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 6, '<');
+ $this->assertFalse($spec->valid());
+ }
+
+ public function testAllowsBothNotEquals() {
+ $spec = new Argil_Specification_Length('123456', 5, '<>');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('123456', 5, '!=');
+ $this->assertTrue($spec->valid());
+
+ $spec = new Argil_Specification_Length('12345', 5, '<>');
+ $this->assertFalse($spec->valid());
+
+ $spec = new Argil_Specification_Length('12345', 5, '!=');
+ $this->assertFalse($spec->valid());
+ }
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|