ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
assClozeGapTest Class Reference

Unit tests. More...

+ Inheritance diagram for assClozeGapTest:
+ Collaboration diagram for assClozeGapTest:

Public Member Functions

 test_instantiateObject_shouldReturnInstance ()
 test_setGetType_shouldReturnUnchangedValue ()
 test_setType_shouldSetDefaultIfNotPassed ()
 test_setGetShuffle_shouldReturnUnchangedValue ()
 test_arrayShuffle_shouldNotReturnArrayUnshuffled ()
 test_addGetItem_shouldReturnValueUnchanged ()
 test_addGetItem_shouldReturnValueUnchangedMultiple ()
 test_getItem_shouldReturnNullIfNoItemAtGivenIndex ()
 test_addGetItem_shouldReturnValueUnchangedMultiplePlus ()
 test_getItems_shouldReturnItemsAdded ()
 test_getItemsWithShuffle_shouldReturnItemsAddedShuffled ()
 test_getItemsRaw_shouldReturnItemsAdded ()
 test_getItemCount_shouldReturnCorrectCount ()
 test_deleteItem_shouldDeleteGivenItem ()
 test_clearItems_shouldClearItems ()
 test_setItemLowerBound_shouldSetItemsLowerBound ()
 test_setItemLowerBound_shouldSetItemsAnswerIfBoundTooHigh ()
 test_setItemUpperBound_shouldSetItemsUpperBound ()
 test_setItemUpperBound_shouldSetItemsAnswerIfBoundTooLow ()
 test_getMaxWidth_shouldReturnCharacterCountOfLongestAnswertext ()
 test_getBestSolutionIndexes_shouldReturnBestSolutionIndexes ()
 test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseText ()
 test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseTextMulti ()
 test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseNumeric ()
 test_getBestSolutionOutput_shouldReturnEmptyStringOnUnknownType_WhichMakesNoSenseButK ()

Protected Member Functions

 setUp ()

Protected Attributes

 $backupGlobals = FALSE

Detailed Description

Unit tests.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de

Definition at line 11 of file assClozeGapTest.php.

Member Function Documentation

assClozeGapTest::setUp ( )
protected

Definition at line 15 of file assClozeGapTest.php.

{
if (defined('ILIAS_PHPUNIT_CONTEXT'))
{
include_once("./Services/PHPUnit/classes/class.ilUnitUtil.php");
ilUnitUtil::performInitialisation();
}
else
{
chdir( dirname( __FILE__ ) );
chdir('../../../');
}
}
assClozeGapTest::test_addGetItem_shouldReturnValueUnchanged ( )

Definition at line 100 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$expected = new assAnswerCloze('Esther', 1.0, 0);
// Act
$instance->addItem($expected);
$actual = $instance->getItem(0);
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_addGetItem_shouldReturnValueUnchangedMultiple ( )

Definition at line 116 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$answer = new assAnswerCloze('Bert', 1.0, 0);
$expected = new assAnswerCloze('Esther', 1.0, 0);
// Act
$instance->addItem($answer);
$instance->addItem($expected);
$actual = $instance->getItem(0);
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_addGetItem_shouldReturnValueUnchangedMultiplePlus ( )

Definition at line 155 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$answer = new assAnswerCloze('Bert', 1.0, 1);
$answer2 = new assAnswerCloze('Fred', 1.0, 2);
$answer3 = new assAnswerCloze('Karl', 1.0, 3);
$expected = new assAnswerCloze('Esther', 1.0, 0);
// Act
$instance->addItem($answer);
$instance->addItem($answer2);
$instance->addItem($answer3);
$instance->addItem($expected);
$actual = $instance->getItem(0);
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_arrayShuffle_shouldNotReturnArrayUnshuffled ( )

Definition at line 85 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
// Act
$the_unexpected = array('Killing', 'Kunkel', 'Luetzenkirchen',
'Meyer', 'Jansen', 'Heyser', 'Becker');
$actual = $instance->arrayShuffle($the_unexpected);
// Assert
$this->assertNotEquals($the_unexpected, $actual);
}
assClozeGapTest::test_clearItems_shouldClearItems ( )

Definition at line 320 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 2);
$item3 = new assAnswerCloze('Karl', 1.0, 1);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = 0;
// Act
$instance->clearItems();
$actual = $instance->getItemCount();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_deleteItem_shouldDeleteGivenItem ( )

Definition at line 297 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 1);
$instance->addItem($item1);
$instance->addItem($item2);
$expected = array('1' => $item2);
// Act
$instance->deleteItem(0);
$actual = $instance->getItemsRaw();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getBestSolutionIndexes_shouldReturnBestSolutionIndexes ( )

Definition at line 457 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 2.0, 2);
$item3 = new assAnswerCloze('Karl', 3.0, 1);
$item4 = new assAnswerCloze('Esther', 4.0, 3);
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = array( 0 => 3 );
// Act
$actual = $instance->getBestSolutionIndexes();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseNumeric ( )

Definition at line 547 of file assClozeGapTest.php.

References $lng.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(2); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(10, 1.0, 0);
$item2 = new assAnswerCloze(20, 2.0, 2);
$item3 = new assAnswerCloze(30, 3.0, 1);
$item4 = new assAnswerCloze(100, 4.0, 3);
// We need the $lng-mock.
require_once './Services/Language/classes/class.ilLanguage.php';
$lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
$lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
global $lng;
$lng = $lng_mock;
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = 100;
// Act
$actual = $instance->getBestSolutionOutput();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseText ( )

Definition at line 482 of file assClozeGapTest.php.

References $lng.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 2.0, 2);
$item3 = new assAnswerCloze('Karl', 3.0, 1);
$item4 = new assAnswerCloze('Esther', 4.0, 3);
// We need the $lng-mock.
require_once './Services/Language/classes/class.ilLanguage.php';
$lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
$lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
global $lng;
$lng = $lng_mock;
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = 'Esther';
// Act
$actual = $instance->getBestSolutionOutput();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getBestSolutionOutput_shouldReturnBestSolutionOutput_CaseTextMulti ( )

Definition at line 514 of file assClozeGapTest.php.

References $lng.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 2.0, 2);
$item3 = new assAnswerCloze('Karl', 4, 1);
$item4 = new assAnswerCloze('Esther', 4, 3);
// We need the $lng-mock.
require_once './Services/Language/classes/class.ilLanguage.php';
$lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
$lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('or') );
global $lng;
$lng = $lng_mock;
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected1 = 'Karl or Esther';
$expected2 = 'Esther or Karl';
// Act
$actual = $instance->getBestSolutionOutput();
// Assert
$this->assertTrue( ($actual == $expected1) || ($actual == $expected2) );
}
assClozeGapTest::test_getBestSolutionOutput_shouldReturnEmptyStringOnUnknownType_WhichMakesNoSenseButK ( )

Definition at line 579 of file assClozeGapTest.php.

References $lng.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(11); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(10, 1.0, 0);
$item2 = new assAnswerCloze(20, 2.0, 2);
$item3 = new assAnswerCloze(30, 3.0, 1);
$item4 = new assAnswerCloze(100, 4.0, 3);
// We need the $lng-mock.
require_once './Services/Language/classes/class.ilLanguage.php';
$lng_mock = $this->getMock('ilLanguage', array('txt'), array(), '', false);
$lng_mock->expects( $this->any() )->method( 'txt' )->will( $this->returnValue('Test') );
global $lng;
$lng = $lng_mock;
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = '';
// Act
$actual = $instance->getBestSolutionOutput();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getItem_shouldReturnNullIfNoItemAtGivenIndex ( )

Definition at line 134 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$answer1 = new assAnswerCloze('Bert', 1.0, 0);
$answer2 = new assAnswerCloze('Esther', 1.0, 1);
$instance->addItem($answer1);
$instance->addItem($answer2);
$expected = null;
// Act
$actual = $instance->getItem(2);
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getItemCount_shouldReturnCorrectCount ( )

Definition at line 254 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 2);
$item3 = new assAnswerCloze('Karl', 1.0, 1);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$expected = 4;
// Act
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$actual = $instance->getItemCount();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getItems_shouldReturnItemsAdded ( )

Definition at line 178 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 1);
$item3 = new assAnswerCloze('Karl', 1.0, 2);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$instance->setShuffle(false);
$expected = array($item1, $item2, $item3, $item4);
// Act
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$actual = $instance->getItems();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getItemsRaw_shouldReturnItemsAdded ( )

Definition at line 231 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 1);
$item3 = new assAnswerCloze('Karl', 1.0, 2);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$expected = array($item1, $item2, $item3, $item4);
// Act
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$actual = $instance->getItemsRaw();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_getItemsWithShuffle_shouldReturnItemsAddedShuffled ( )

Definition at line 202 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
$instance->setShuffle(true);
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 1);
$item3 = new assAnswerCloze('Karl', 1.0, 2);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$expected = array($item1, $item2, $item3, $item4);
// Act
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$actual = $instance->getItems();
// Assert
$this->assertTrue(is_array($actual));
$this->assertTrue(in_array($item1, $actual));
$this->assertTrue(in_array($item2, $actual));
$this->assertTrue(in_array($item3, $actual));
$this->assertTrue(in_array($item4, $actual));
$this->assertNotEquals($expected, $actual);
}
assClozeGapTest::test_getMaxWidth_shouldReturnCharacterCountOfLongestAnswertext ( )

Definition at line 432 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze('Bert', 1.0, 0);
$item2 = new assAnswerCloze('Fred', 1.0, 2);
$item3 = new assAnswerCloze('Karl', 1.0, 1);
$item4 = new assAnswerCloze('Esther', 1.0, 3);
$instance->addItem($item1);
$instance->addItem($item2);
$instance->addItem($item3);
$instance->addItem($item4);
$expected = strlen($item4->getAnswertext());
// Act
$actual = $instance->getMaxWidth();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_instantiateObject_shouldReturnInstance ( )

Definition at line 29 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
// Act
$instance = new assClozeGap(0); // 0 - text gap
$this->assertInstanceOf('assClozeGap', $instance);
}
assClozeGapTest::test_setGetShuffle_shouldReturnUnchangedValue ( )

Definition at line 70 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
$expected = true;
// Act
$instance->setShuffle($expected);
$actual = $instance->getShuffle();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_setGetType_shouldReturnUnchangedValue ( )

Definition at line 40 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
$expected = 1; // 1 - select gap
// Act
$instance->setType($expected);
$actual = $instance->getType();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_setItemLowerBound_shouldSetItemsAnswerIfBoundTooHigh ( )

Definition at line 367 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(20, 1.0, 0);
$instance->addItem($item1);
$expected = 40;
// Act
$instance->setItemLowerBound(0, $expected);
$item_retrieved = $instance->getItem(0);
$actual = $item_retrieved->getLowerBound();
// Assert
$this->assertNotEquals($expected, $actual);
$this->assertEquals($item_retrieved->getAnswerText(), $actual);
}
assClozeGapTest::test_setItemLowerBound_shouldSetItemsLowerBound ( )

Definition at line 346 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(20, 1.0, 0);
$instance->addItem($item1);
$expected = 10;
// Act
$instance->setItemLowerBound(0, $expected);
$item_retrieved = $instance->getItem(0);
$actual = $item_retrieved->getLowerBound();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_setItemUpperBound_shouldSetItemsAnswerIfBoundTooLow ( )

Definition at line 410 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(20, 1.0, 0);
$instance->addItem($item1);
$expected = 10;
// Act
$instance->setItemUpperBound(0, $expected);
$item_retrieved = $instance->getItem(0);
$actual = $item_retrieved->getUpperBound();
// Assert
$this->assertNotEquals($expected, $actual);
$this->assertEquals($item_retrieved->getAnswerText(), $actual);
}
assClozeGapTest::test_setItemUpperBound_shouldSetItemsUpperBound ( )

Definition at line 389 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
require_once './Modules/TestQuestionPool/classes/class.assAnswerCloze.php';
$item1 = new assAnswerCloze(5, 1.0, 0);
$instance->addItem($item1);
$expected = 10;
// Act
$instance->setItemUpperBound(0, $expected);
$item_retrieved = $instance->getItem(0);
$actual = $item_retrieved->getUpperBound();
// Assert
$this->assertEquals($expected, $actual);
}
assClozeGapTest::test_setType_shouldSetDefaultIfNotPassed ( )

Definition at line 55 of file assClozeGapTest.php.

{
// Arrange
require_once './Modules/TestQuestionPool/classes/class.assClozeGap.php';
$instance = new assClozeGap(0); // 0 - text gap
$expected = 0; // 0 - text gap
// Act
$instance->setType();
$actual = $instance->getType();
// Assert
$this->assertEquals($expected, $actual);
}

Field Documentation

assClozeGapTest::$backupGlobals = FALSE
protected

Definition at line 13 of file assClozeGapTest.php.


The documentation for this class was generated from the following file: