public function testIntegerToFloat()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = new Integer(10);
     $processor = new IntegerToFloatProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(10.0, $result->getValue());
     $operands->reset();
     $operands[] = new Integer(-10);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(-10.0, $result->getValue());
     $operands->reset();
     $operands[] = new Integer(0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(0.0, $result->getValue());
     $operands->reset();
     $operands[] = new Integer(-0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(-0.0, $result->getValue());
 }
示例#2
0
 public function testRound()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = new QtiFloat(6.8);
     $processor = new RoundProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(7, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(6.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(7, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(6.49);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(6, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(6.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(7, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(-6.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(-6, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(-6.51);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(-7, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(-6.49);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(-6, $result->getValue());
     $operands->reset();
     $operands[] = new QtiInteger(0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(-0.0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new QtiFloat(-0.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\QtiInteger', $result);
     $this->assertEquals(0, $result->getValue());
 }
示例#3
0
 public function testNull()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection(array(new QtiInteger(10), null));
     $processor = new SubtractProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::FLOAT);
     $result = $processor->process();
     $this->assertSame(null, $result);
 }
示例#4
0
 public function testNotEmpty()
 {
     $expression = $this->getFakeExpression();
     $operands = new OperandsCollection(array(new QtiInteger(0)));
     $processor = new IsNullProcessor($expression, $operands);
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new QtiBoolean(false);
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new QtiInteger(-1);
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new QtiPoint(1, 2);
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::INTEGER, array(new QtiInteger(25)));
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new OrderedContainer(BaseType::POINT, array(new QtiPoint(3, 4), new QtiPoint(5, 6)));
     $this->assertFalse($processor->process()->getValue());
     $operands->reset();
     $operands[] = new RecordContainer(array('a' => new QtiBoolean(true), 'b' => null, 'c' => new QtiPoint(1, 2), 'd' => new QtiInteger(24), 'e' => new QtiFloat(23.3)));
     $this->assertFalse($processor->process()->getValue());
 }
示例#5
0
 public function testLte()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = new Float(0.5);
     $operands[] = new Integer(1);
     $processor = new LteProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertTrue($result->getValue());
     $operands->reset();
     $operands[] = new Integer(1);
     $operands[] = new Float(0.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertFalse($result->getValue());
     $operands->reset();
     $operands[] = new Integer(1);
     $operands[] = new Integer(1);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertTrue($result->getValue());
 }
 public function testSize()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = new MultipleContainer(BaseType::STRING, array(new String('String!')));
     $processor = new ContainerSizeProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertEquals(1, $result->getValue());
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(1, 2), new Point(2, 3), new Point(3, 4)));
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(3, $result->getValue());
 }
 public function testNull()
 {
     $expression = $this->createFakeExpression(false);
     $operands = new OperandsCollection();
     $operands[] = new String('test');
     $operands[] = null;
     $processor = new SubstringProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new String('');
     // in QTI, empty string considered to be NULL.
     $operands[] = new String('blah!');
     $result = $processor->process();
     $this->assertSame(null, $result);
 }
 public function testMixed()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection(array(new Integer(10), new Float(26.4), new Integer(-4), new Float(25.3)));
     $processor = new MinProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(-4.0, $result->getValue());
     $operands->reset();
     $operands[] = new OrderedContainer(BaseType::INTEGER, array(new Integer(2), new Integer(3), new Integer(1), new Integer(4), new Integer(5)));
     $operands[] = new Float(2.4);
     $operands[] = new MultipleContainer(BaseType::FLOAT, array(new Float(245.4), new Float(1337.1337)));
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(1.0, $result->getValue());
 }
示例#9
0
 public function testNull()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     // second operand is null.
     $operands[] = new QtiInteger(10);
     $operands[] = new OrderedContainer(BaseType::INTEGER);
     $processor = new MemberProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertSame(null, $result);
     // fist operand is null.
     $operands->reset();
     $operands[] = null;
     $operands[] = new MultipleContainer(BaseType::INTEGER, array(new QtiInteger(10)));
     $result = $processor->process();
     $this->assertSame(null, $result);
 }
 public function testNull()
 {
     // exp as a float is NaN when negative base is used.
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection(array(new Integer(-20), new Float(3.4)));
     $processor = new PowerProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new Integer(1);
     $operands[] = null;
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::FLOAT);
     $operands[] = new Integer(2);
     $result = $processor->process();
     $this->assertSame(null, $result);
 }
示例#11
0
 public function testFile()
 {
     $fManager = new FileSystemFileManager();
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $file1 = $fManager->createFromData('Some text', 'text/plain');
     $file2 = $fManager->createFromData('Some text', 'text/plain');
     $operands[] = $file1;
     $operands[] = $file2;
     $processor = new MatchProcessor($expression, $operands);
     $this->assertTrue($processor->process()->getValue());
     $fManager->delete($file1);
     $fManager->delete($file2);
     $operands->reset();
     $file1 = $fManager->createFromData('Some text', 'text/plain');
     $file2 = $fManager->createFromData('Other text', 'text/plain');
     $operands[] = $file1;
     $operands[] = $file2;
     $this->assertFalse($processor->process()->getValue());
     $fManager->delete($file1);
     $fManager->delete($file2);
 }
示例#12
0
 public function testComplexMultipleInBetween()
 {
     $expression = $this->createFakeExpression();
     // For ordered containers [A,B,C,D] contains [B]
     $operands = new OperandsCollection();
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(1, 2), new Point(3, 4), new Point(5, 6), new Point(7, 8)));
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(3, 4)));
     $processor = new ContainsProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertTrue($result->getValue());
     // [A,B,C,D] does not contain [E]
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(1, 2), new Point(3, 4), new Point(5, 6), new Point(7, 8)));
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(9, 10)));
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertFalse($result->getValue());
     // [A,B,C,D] contains [A,D]
     $operands->reset();
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(1, 2), new Point(3, 4), new Point(5, 6), new Point(7, 8)));
     $operands[] = new MultipleContainer(BaseType::POINT, array(new Point(1, 2), new Point(7, 8)));
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Boolean', $result);
     $this->assertTrue($result->getValue());
 }
示例#13
0
 public function testRound()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = new Float(6.8);
     $processor = new TruncateProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(6, $result->getValue());
     $operands->reset();
     $operands[] = new Float(6.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(6, $result->getValue());
     $operands->reset();
     $operands[] = new Float(6.49);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(6, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-6.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(-6, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-6.8);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(-6, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-6.49);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(-6, $result->getValue());
     $operands->reset();
     $operands[] = new Integer(0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-0.0);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-0.5);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-0.4);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new Float(-0.6);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Integer', $result);
     $this->assertEquals(0, $result->getValue());
     $operands->reset();
     $operands[] = new Float(NAN);
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new Float(-INF);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(-INF, $result->getValue());
     $operands->reset();
     $operands[] = new Float(INF);
     $result = $processor->process();
     $this->assertInstanceOf('qtism\\common\\datatypes\\Float', $result);
     $this->assertEquals(INF, $result->getValue());
 }
示例#14
0
 public function testNull()
 {
     $expression = $this->createFakeExpression();
     $operands = new OperandsCollection();
     $operands[] = null;
     $operands[] = new MultipleContainer(BaseType::INTEGER, array(new Integer(0), new Integer(10), new Integer(20), new Integer(30)));
     $processor = new DeleteProcessor($expression, $operands);
     $result = $processor->process();
     $this->assertSame(null, $result);
     $operands->reset();
     $operands[] = new Integer(10);
     $operands[] = new MultipleContainer(BaseType::INTEGER);
     $result = $processor->process();
     $this->assertSame(null, $result);
 }