; FILENAME: au3FlashCards.au3
; PURPOSE: Functions to suport a flash card program
;
; INITIAL NOTES:
#cs FILEFORMAT:
; au3 flashcard card format
; Select card type. Write question. Write optional answers seperated by |. Correct answer is enclosed by [].
; card type:=text|option|checkbox|mathdrill|mathformula
; question:= What is a horse
; Answer options:=fruite|flower|[animal]
[text card]
; Check agains matching text
; Check agains text pattern
[option card]
; check agains selected regular text based option.
; Check agains slected picture based option.
[checkbox card]
; Chek agains slected check boxes
[math drill]
; Check agains answer or formula? Formula could check agains answers by using the formula?
#CE - FILEFORMAT
#include-once
#include <dbgtools.au3>
#include <au3FlashCardsTest.au3>
AutoitSetOption('MustDeclareVars',1)
global $gfsDeckNames = ''
global $gfsCurrentDeckID = 0
Global $gfsCurrentCardID = 0
global $gfsArrDecks[1] = [0]
global $gfsDeckMode = ''
Global Enum $gfsEnumDeckMode0, $gfsEnumDeckMode1
Func __fsGetQuizType(ByRef $quizData)
; Return quiz type
;text|option|checkbox|mathdrill|mathformula
If not IsArray($quizData) Then Return SetError(1,0,0)
For $i = 1 to $quizData[0][0]
If $quizData[$i][0] == 'CardType' Then ExitLoop
Next
If $i > $quizData[0][0] Then Return SetError(2,0,0)
Return $quizData[$i][1]
EndFunc
func _fsCloseDecks()
$gfsDeckMode = ''
$gfsArrDecks[0] = 0
$gfsCurrentCardID = 0
$gfsCurrentDeckID = 0
$gfsDeckNames = ''
EndFunc
Func _fsOpenDecks($deckNames, $deckMode=$gfsEnumDeckMode0)
; Return True on success, false on error
; $deckNames is a | delimited list of pathnames (or ID) to ini(later on z7) files containing a deck.
; $deckMode = 0 --> sequential shufeling in _fsShufleDecks()
; $deckMode = 1 --> random shufeling in _fsShufleDecks()
;
; @error = 1, @extended=0: The one filename provided could not be located.
; @error = 1, @extended>0: File nr @extended in the list could not be located.
; Make sure we have an array
Local $arr , $i
If IsArray($decknames) then
$arr = $decknames
Else
$arr = StringSplit($deckNames, '|')
EndIf
If $arr[0] == 1 then
If not FileExists($arr[1]) Then
err('Could not locat deck file: ' & $arr[1],@ScriptLineNumber-1, 1,0)
$gfsArrDecks[0] = 0
$gfsCurrentDeckID = 0
Return SetError(1,0, false)
EndIf
Else
For $i = 1 to $arr[0]
if $arr[$i] <> "" then
If Not FileExists($arr[$i]) Then
err('Could not locat deck file:' & $arr[$i] & ' in ' & @WorkingDir,@ScriptLineNumber-1, 1,0)
$gfsArrDecks[0] = 0
$gfsCurrentDeckID = 0
; Return @error=1 and @extended = index of missing file.
Return SetError(1, $i, false)
EndIf
EndIf
Next
EndIf
$gfsArrDecks = $arr
$gfsDeckMode = $deckMode
; TODO: How does $deckMode affect first $gfsCurrentDeckID?
$gfsCurrentDeckID = 1
Return true
EndFunc
Func _fsShufleDecks()
; If several decks are provided in _fsOpenDecks then set current deck to use
; If _fsOpenDecks has not been called return error.
;
; @error=1: No files in the list. Need to call _fsOpenDecks
If Not IsArray($gfsArrDecks) Then Return SetError(1,0,'')
; Shuffle
If $gfsArrDecks[0] == 0 then
err('deck count=0. Need valide call to _fsOpenDecks(...)')
Return SetError(1,0,0)
ElseIf $gfsArrDecks[0] == 1 Then
$gfsCurrentDeckID = 1
Else
$gfsCurrentDeckID = Random(1, $gfsArrDecks[0], 1)
EndIf
Return $gfsArrDecks[$gfsCurrentDeckID]
EndFunc
Func _fsGetCurrentDeck()
; Return current deck pathname (or ID)
If $gfsCurrentDeckID == 0 Then
err('no available decks.Make call to _fsOpendecks(...)?')
Return SetError(1,0, '')
EndIf
;
Return $gfsArrDecks[$gfsCurrentDeckID]
EndFunc
Func _fsSetCurrentDeck($deck)
;@error=1, @extended=0: deck not in list
;@error=2, $extended=MAX_ID; ID Out of bounds
;@error=2, $extended=0; ID equals 0
Local $i
If IsNumber($deck) Then
If $deck == 0 then
Return SetError(2, 0, $gfsArrDecks[$gfsCurrentDeckID])
ElseIf $deck >= $gfsArrDecks[0] Then
Return SetError(2, $gfsArrDecks[0], $gfsArrDecks[$gfsCurrentDeckID])
Else
$gfsCurrentDeckID = $deck
EndIf
Else
For $i = 1 to $gfsArrDecks[0]
If $deck == $gfsArrDecks[$i] Then
$gfsCurrentDeckID = $i
ExitLoop
EndIf
Next
If $i > $gfsArrDecks[0] Then
; deck asked for is not in list. Make new call to _fsOpenDecks
Return SetError(2, 0, $gfsArrDecks[$gfsCurrentDeckID])
EndIf
EndIf
Return $gfsArrDecks[$gfsCurrentDeckID]
EndFunc
Func __fsGetCardList(ByRef $arrCards, $deck='')
; Get deck information
If $deck = '' Then $deck = _fsGetCurrentDeck()
If err('_fsGetCurrentDeck():=' & $deck & ', missing call to _fsOpendecks()?') then Return SetError(@error, @extended, 0)
;
; Get cards count and reference information
$arrCards = IniReadSectionNames($deck)
if err('IniReadSectionNames(' & $deck & ') failed. Could not locate any cards in the deck') Then Return SetError(2,0,0)
Return True
EndFunc
Func _fsGetNextCard(ByRef $quizdata, $previousID=-1)
; RETURN 0 if there is no next card or on error.
; ByRef $question: Returns a string with the question.
; ByRef $answers: Returns an array with the answer sugestions.
; ByRef $type: Returns a string with answer type information.
; $previousID: Optional. Provide Id of the previous question. If the deck was opened in
; sequential mode the next card id is delivered.
;
; @error = 1: $previousID > _fsGetLastCardID()
; Next card ddepends upon the deck (application mode) to use.
; It allso depends on the card uised last in that deck.
; Who is responsible for shuffeling decks?
; TODO: Should ther be some kind of history tracking in the cards?
;
; ChangeLog:
; Changed interface from
; (byref $question, byref $answers, byref $type, $previousID)
; To:
; (byref $quizdata, $previousID)
; $quizdata does now contain the an two dimentional array where [n][0] = keyname and
; [n][1] is the data. [0][0] contains the last index in the array.
Local $cardID=0, $cardList
Local $deck = _fsGetCurrentDeck()
;
If err('__fsGetCardList(...)' & __fsGetCardList($cardList)) Then return SetError(@error, @extended, 0)
Local $cardID
Switch $gfsDeckMode
case 0
;Check if we have a valide previousID
; $previousID <> -1 The caller has determined witch card to get.
If $previousID < -1 OR $previousID > $cardList[0]-1 Then Return SetError(4,0,0)
$cardID = _fsGetNextCardID($gfsDeckMode, $previousID)
case 1
assertNoCode()
case 2
assertNoCode()
EndSwitch
If Not _fsGetCardByID($quizdata, $cardID) Then Return SetError(@error, @extended, 0)
;
; Read next card from selected deck
; If err('_fsgetnextCardID(' & $previousID & ') failed.') Then
; assertNoCode()
; Else
; ; Check validity of cardID and read the card if it is valide.
; if $cardID > $cardList[0] then
; ; TODO: error or Next deck or start from begining?
; Return SetExtended(11,0)
; Else
; ; card ok. read it and return the values
; $quizdata = IniReadSection($deck, $cardList[$cardID])
; If err('InireadSection(' & $deck & ', ' & $cardList[$cardID] & ') failed') then
; Return setError(12, 0, 0)
; EndIf
; EndIf
; EndIf
return $cardID
EndFunc
Func _fsGetLastCardID()
; Return last cardID in Current deck
; @error:=1, @exteneded:=0 > Missing deck file? Call _fsopenDecks(...)
Local $deck = _fsGetCurrentDeck()
If not err('call to _fsGetCurrentDeck() failed. No current deck?') Then
Local $sn = IniReadSectionNames($deck)
If err('_fsGetLastCardID: Could not read section names in ' & _fsGetCurrentDeck()) Then
Return SetError(@error, @extended, 0)
EndIf
Else
Return SetError(@error, @extended, 0)
EndIf
Return $sn[0]
EndFunc
Func _fsSetCurrentCardID($cardID)
; External Overide of sequence
$gfsCurrentCardID = $cardID
EndFunc
func _fsGetNextCardID($fsMode=0, $previousID=-1)
; Determine deck based on information provided in _fsOpenDeck$
; Get the next cardID. Thyis could depend on $fsMode indicating
; 0=sequensial read,
; 1=random but not allready read in this session
; 2=Memory access mode (1,+3,+7,+14,+30,+90,+180,+352)
Local $ret=0
If _fsGetCurrentDeck() == '' Then
err('No deck available')
Return SetError(1,0,0)
EndIf
Switch $gfsDeckMode
case 0 ;Sequential read. Read until last card in deck.
;Then Switch to next deck in array. Repet until last card.
If $previousID >= 0 Then
If $previousID <= _fsGetLastCardID() -1 Then
$ret = $previousID + 1
Else
; The caller must shufle or set next deck
; NOTE: Should SetExteneded be done to indicate why return is 0?
assertNoCode('NO CODE Should the caller or I shufle and set next deck?')
$ret = 0
EndIf
ElseIf $gfsCurrentCardID <= _fsGetLastCardID() Then
$gfsCurrentCardID += 1
$ret = $gfsCurrentCardID
Else
; First card in next deck
$gfsCurrentCardID = 1
$gfsCurrentDeckID += 1
If $gfsCurrentDeckID > $gfsArrDecks[0] Then $gfsCurrentDeckID = 1
assertNoCode('NO CODE Sequential read. Read until last card in deck is implemented but what about faulty answers?.')
EndIf
case 1 ; Random but no repetition (of correctly answered card)
assertNoCode('NO CODE Random mode functionality not implemented')
case 2 ; Memory access (strengthening) mode (1,+3,+7,+14,+30,+90,+180,+352)
assertNoCode('NO CODE Memory access/strengthening functionality not implemented')
EndSwitch
Return $ret
EndFunc
Func _fsGetCardByID(ByRef $quizdata, $cardID, $line=@ScriptLineNumber)
;Read card matching
; @error=1, @extended=0 : Missing call to _fsOpenDecks?
; Changed interface from (ByRef $question, ByRef $answer, $cardID)
; to: (ByRef $quizdata, $cardID)
Local $cardList
Local $deck = _fsGetCurrentDeck()
If err(__fsGetCardList($cardList, $deck)) Then return SetError(@error, @extended, 0)
; Makse sure we dont acces out of bounds
If $cardList[0] < $cardID OR $cardID < 1 Then Return SetError(4,0,0)
$quizdata = IniReadSection($deck, $cardList[$cardID])
If err('InireadSection(' & $deck & ', ' & $cardList[$cardID] & ') failed') then Return setError(3, 0, 0)
Return True
EndFunc
Func _fsCheckAnswer($answer, $cardID)
; RETURN: True or false
; Check answer given against $cardID
; The answer is a | delimited list or array.
Local $quizData, $i, $j, $answers
If not IsArray($answer) Then $answers = StringSplit($answer, '|')
If err(_fsGetCardByID($quizData,$cardID)) then Return SetError(@error, @extended, false)
if not IsArray($quizData) Then Return SetError(19,0,false)
For $i = 1 to $quizData[0][0]
If $quizData[$i][0] == 'answer' Then ExitLoop
Next
If $i > $quizData[0][0] then Return SetError(20,0,False)
For $j = 1 to $answers[0]
if not StringInStr($quizdata[$i][1], __fsStringBracketClose($answers[$j])) Then
todo('Add tracking functionality')
Return SetExtended($j,False)
EndIF
Next
Return True
EndFunc
Func __fsStringBracketClose($str)
Local $ret = $str
If Not (StringLeft($str,StringLen('[')) == '[') Then $ret = '[' & $ret
If Not (StringRight($str,StringLen(']')) == ']') Then $ret = $ret & ']'
Return $ret
EndFunc
Func _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)
; $bool = true or false determines if the giwen asver was correct.
; TODO: Personal or global tracking of answers?
; Personal Tracking and recording is prefered.
; Application is portableapps compatible as efault
; Application ini could overide this and create tracking IniDelete
; in profile folder.
assertNoCode()
EndFunc
Func test_fsRecordAnswer()
; _fsRecordAnswer($bool, $cardID, $fsMode=0, $static=0)
; $bool = true or false determines if the giwen asver was correct.
; _fsWriteTrackRecord($bool, $cardID, $fsMode=0)
; TODO: Personal or global tracking of answers?
; Personal Tracking and recording is prefered.
; Application is portableapps compatible as efault
; Application ini could overide this and create tracking IniDelete
; in profile folder.
;
; Logging correct or false answers could be done by means of an MRU list
; MRUwrong = 3 6 11
Local $section = @username & '@' & @computername & '::' & _fsGetCurrentDeck()
assertNoCode()
_fsCloseDecks()
EndFunc
If StringLeft(@ScriptName, StringLen(@scriptname)-4) == 'au3FlashCards' Then suite_au3FlashCardstest()oÝ÷ Ù¶®ÜYZ²ÛzËZ»Ûjëh×6; FILENAME: au3FlashCardsTest.au3
; PURPOSE: Unit test collection against au3FlashCards.au3
#include-once
#include <au3FlashCards.au3>
#include <dbgtools.au3>
#region - Global variables
Global $test_fsGetLastCardID = 4
Global $test_fsGetCurrentDeck = 'Test_au3FlashCards.ini'
Global $fstsr = 0 ; flash card test sucess rate
Global $test_DeckWithCorruptData = 'DeckWithCoruptData.ini'
Global $test_deckWithNoCards = 'DeckWithNoCards.ini'
Global $test_TestDecks='testDeck1.ini|testDeck2.ini|testDeck3.ini'
Global $test_fsArrTestDecks = StringSplit($test_TestDecks,'|')
#EndRegion - Global variables
#Region - test common maintenance routines
Func testCreateTestDeckAndData($iniFile, $fresh=true)
; PURPOSE: Creat test data:
;dbg('TESTDATA: ' & $inifile & ' in ' & @WorkingDir)
If $fresh AND FileExists($iniFile) then FileDelete($iniFile)
; Use as identifier in the test
assert(IniWriteSection($iniFile, StringRight($iniFile, StringLen($iniFile) - StringInStr($iniFile, '', 0, -1)), 'pathname=' & $inifile))
; Various sections following the quiz crad format
assert(IniWriteSection($iniFile, 'quiz_1','CardType=text' & @CRLF & _
'question=Can you ride on a horse?' & @CRLF & _
'answer=[yes]|[you can]|[ofcource]'))
assert(iniWriteSection($iniFile, 'quiz_2', 'CardType=option' & @CRLF & _
'question=The capitol of Norway is named?' & @CRLF & _
'answer=[Oslo]|Stocholm|Copenhagen|Paris' & @CRLF & _
'image=OsloTownHall.jpg' & @CRLF & _
'link=en.wikipedia.org/norway'))
assert(iniWriteSection($iniFile, 'quiz_3', 'CardType=check' & @CRLF & _
'question=A dolphine is' & @CRLF & _
'answer=[a mamal]|[a see mamal]|[a clever animal]|a shark,a wale,a fish,a land animal' & @CRLF & _
'image=dolphine.jpg' & @CRLF & _
'link=en.wikipedia.org/dolphine'))
assert(IniWriteSection($iniFile, 'quiz_4', 'CardType=image option' & @CRLF & _
'question=Select the picture displaying a valve' & @CRLF & _
'answer=house.jpg|img2.jpg|[house.jpg]|cotage.jpg'))
err('While writing test data.')
EndFunc
Func testCreateTestDeckWithNoCards($iniFile, $fresh=true)
If $fresh AND FileExists($iniFile) then FileDelete($iniFile)
FileWriteLine($inifile,'')
EndFunc
Func testCreateTestDeckWithCorruptData($iniFile, $fresh=true)
If $fresh AND FileExists($iniFile) then FileDelete($iniFile)
IniWriteSection($iniFile,'EmptySection','')
EndFunc
Func testCreateData($force=false)
;dbg('testCreateData: @workingdir:=' & @WorkingDir)
Local $i
For $i = 1 to $test_fsArrTestDecks[0]
testCreateTestDeckAndData($test_fsArrTestDecks[$i], $force)
assert(FileExists($test_fsArrTestDecks[$i]), 'Could not locate: ' & $test_fsArrTestDecks[$i] & ' in ' & @WorkingDir)
Next
EndFunc
Func testCleanUp($rootDir = @Workingdir, $line=@ScriptLineNumber)
;dbg('testCleanUp: @rootDir:=' & $rootDir & ', @workingDir:=' & @Workingdir, $line)
Local $i
_fsCloseDecks()
For $i = 1 to $test_fsArrTestDecks[0]
If FileExists($rootDir & '' & $test_fsArrTestDecks[$i]) Then
FileDelete($rootDir & '' & $test_fsArrTestDecks[$i])
ElseIf FileExists($test_fsArrTestDecks[$i]) Then
FileDelete($rootDir & '' & $test_fsArrTestDecks[$i])
EndIf
If FileExists($rootDir) Then err(DirRemove($rootDir, true))
Next
If FileExists($test_DeckWithCorruptData) Then err(FileDelete($test_DeckWithCorruptData) & ' FileDelete failed?')
If FileExists($test_deckWithNoCards) Then err(FileDelete($test_deckWithNoCards) & ' FileDelete failed?')
EndFunc
#EndRegion - test common maintenance routines
; ---------------------------------------------
#Region - test suite routines
Func RunTest($testName, $line=@ScriptLineNumber)
dbg('RunTest:' & $testName, $line)
errSupress('',false)
Call ($testName)
err('Call(' & $testName & ') failed',$line)
EndFunc
func suite_au3FlashCardstest()
dbg('--- START suite_au3FlashCardstest ---')
; Do work in a temp dir.
Local $dir = @Workingdir
local $workDir = @TEMPDIR & '\au3FlashCards'
If not FileExists($workDir) then DirCreate($workDir)
assert(FileChangeDir($workDir))
; Create som valide test data. SOme tests require faulty or corrup data
; They are responisble for calling the apropriate support functions to
; create such data. Or create it themselves and clean up afterwards.
testCreatedata()
; Test deck logic
Local $testall = false
If $testall Then RunTest('test_fsOpenDecks')
If $testall Then RunTest('test_fsShufleDecks')
If $testall Then RunTest('test_fsGetCurrentDeck')
If $testall Then RunTest('test_fsSetCurrentDeck')
;
; Test card logic
;
If $testall Then RunTest('test_fsGetLastCardID')
If $testall Then RunTest('test_fsGetNextCardID')
If $testall Then RunTest('test_fsGetNextCard')
If $testall Then RunTest('test_fsGetCardByID')
If $testall Then RunTest('test__fsGetQuizType')
If $testall Then RunTest('test_fsCheckAnswer')
If true Then RunTest('test_fsRecordAnswer')
; Utility functions
if $testall Then RunTest('test___fsStringBracketClose')
testCleanUp($workDir)
assert(FileChangeDir($dir))
dbg('--- END suite_au3FlashCardstest ---')
assertreport()
EndFunc
#EndRegion - test suite routines
; ---------------------------------------------
Func arrDump2(Byref $arr)
Local $i
For $i = 0 to UBound($arr)-1
dbg('(' & $i & ') ' & $arr[$i][0] & ' - ' & $arr[$i][1])
Next
EndFunc
Func testSetupOpenDecks()
; Open a valide set of decks
assert(_fsOpenDecks($test_fsArrtestDecks),' _fsOpenDecks(...) should return true')
EndFunc
Func test_fsCheckAnswer()
; _fsCheckAnswer($answer, $cardID)
; RETURN: True or false
; Check answer given against $cardID
; the answer type depends on the quiz type (text, option, checbox...
;
Local $quiz, $errS = false
; TEST: error handeling
$errS = errSupress('', true)
; _fsCheckAnswer use _fsGetCardByID and returns the same errors.
; TODO: test_fsGetCardByID should take care of most of the error tests
assert(false == _fsCheckAnswer('master test', 5))
assertErr(1,0, '_fsCheckAnswer use _fsGetCardByID and returns the same errors when called prior to a _fsOpenDecks(...) call.')
;_fsOpenDecks($test_deckWithNoCards)
_fsOpenDecks($test_fsArrTestDecks)
assert(false == _fsCheckAnswer('nada, nada',1)) ; The first entry is supposed to contain file information?
assertErr(20,0,'the answer field could not be located in the collection.')
assert(false == _fsCheckAnswer('nada, nada',2))
assertErr(0,1,'@extended is supposed to be the answer id that failed to pass.')
assert(false == _fsCheckAnswer('yes|ofcource|duh',2))
assertErr(0,3,'@extended is supposed to be the answer id that failed to pass (expected 3).')
errSupress('',$errS)
; TEST: Functionality.
_fsOpenDecks($test_fsArrTestDecks)
assert(_fsCheckAnswer('ofcource',2))
_fsCheckAnswer('yes',2)
_fsCloseDecks()
EndFunc
Func test_fsGetLastCardID()
;Call to _fsGetNextCard(...) without previous call to _fsOpenDecks should return 0 and set @error=1')
Local $errS = errSupress()
assertErr(1, 0, 'Expect call to _fsGetLastCardID(...) to return 0:=' & _fsGetLastCardID() & ' and @error=1')
errSupress($errS)
; So open valide deck set
testSetupOpenDecks()
; Return last cardID in Current deck
assert(5 = _fsGetLastCardID(), 'Expected _fsGetLastCradID():=5 Validate data in deck' & _fsGetCurrentDeck() & ' ?' )
_fsCloseDecks()
EndFunc
Func test_fsGetNextCard()
todo('test_fsGetNextCard(): Verify diffrent modes. Currently only mode 0 is tested/implemented.')
Local $quizdata, $foo, $i, $errS
;
; TEST: Call to _fsGetNextCard(...) without previous call to _fsOpenDecks should return 0 and set @error=1')
$errS = errSupress()
assertErr(1, 0, 'Expect call to _fsGetNextCard(...) to return 0:=' & _fsGetNextCard($quizdata) & ' and @error=1')
errSupress($errS)
;
; TEST: after call to _fsOpenDecks
; Open a set of decks
testSetupOpenDecks()
;
; TEST: The first card is a special case
$foo = _fsGetNextCard($quizdata)
assert(0 < $foo, '_fsGetNextCard(...) should return something (:=' & $foo & ') on first call after _fsopenDeck.')
assert(IsArray($quizdata))
;
; TEST: get the rest of the cards
For $i = 2 to 5 ; 5 entries in the first deck?
$foo = _fsGetNextCard($quizdata)
If not assert(IsArray($quizdata),'Expected array? cardID:=' & $foo) then exitloop
;dbg('cardID:= ' & $foo & ' $quizdata[0][0]:=' & $quizdata[0][0])
If Not assert($quizdata[0][0] > 0 ) Then
dbg('uhh, what happend? no elements in returned array?')
Else
;arrDump2($quizdata)
EndIf
Next
;
; TEST: Conditions when we move to a cardID beyond the last
$foo = _fsGetNextCard($quizdata)
assertErr(4, 0, 'Expected error after a call to a card beyond the last card in the deck')
$foo = _fsGetNextCard($quizdata, 99)
assertErr(4, 0, 'Expected error after a call to a card beyond the last card in the deck')
;
; TEST: Test agains user determined card position.
$foo = _fsGetNextCard($quizdata,2)
assert($foo = 3, 'Expected the third card in deck 1' )
assert($quizdata[4][0] = 'image')
assert($quizdata[4][1] = 'OsloTownHall.jpg')
_fsCloseDecks()
EndFunc
Func test_fsGetNextCardID()
; _fsGetNextCardID( $fsMode=0, $previousID=-1)
; Determine deck based on information provided in _fsOpenDecks
; Get the next cardID. Thyis could depend on $fsMode indicating
; 0=sequensial read,
; 1=random but not allready read in this session
; 2=Memory access mode (1,+3,+7,+14,+30,+90,+180,+352)
; mode=0 Sequencial read
Local $cardIDs[3]
; Test error conditions
Local $errS = errSupress()
assertErr(1, 0, '_fsGetNextCard(...) should return error and 0 when called prior to _fsOpenDecks(...) call: ' & _fsGetNextCardID())
errSupress($errS)
; Test normal working conditions
testSetupOpenDecks()
assert(_fsGetNextCardID(0) = 1, '_fsGetNextCardID(1,0) returned unexpected result')
; This call should not affect a new call with (0)
assert(_fsGetNextCardID(0, 2) = 3, '_fsGetNextCardID(1,0) returned unexpected result')
assert(_fsGetNextCardID(0, 3) = 4, '_fsGetNextCardID(1,0) returned unexpected result')
assert(_fsGetNextCardID(0) = 2, '_fsGetNextCardID(1,0) returned unexpected result')
assert(_fsGetNextCardID(0, -1) = 3, '_fsGetNextCardID(1,0) returned unexpected result')
; mode=1
todo('test_fsGetNextCardID deck mode=1 not implemented')
; mode=2
todo( 'test_fsGetNextCardID deck mode=2 not implemented')
_fsCloseDecks()
_fsCloseDecks()
EndFunc
Func test_fsGetCardByID()
Local $errS, $data
; _fsGetCardByID(ByRef $question, ByRef $answer, $cardID)
;Read card matching
; Test error condition
$errS = errSupress('',true)
; No open decks
_fsGetCardById($data,1)
assertErr(1,0, 'Expects error when calling _fsGetCardByID before calling _fsOpenDecks()')
; No cards in curent deck.
testCreateTestDeckWithNoCards($test_DeckWithNoCards)
_fsOpenDecks($test_DeckWithNoCards)
_fsGetCardById($data,1)
assertErr(2,0,'Expected IniReadSectionNames to fail.')
; No data in current card
testCreateTestDeckWithCorruptData($test_DeckWithCorruptData)
_fsOpenDecks($test_DeckWithCorruptData)
_fsGetCardById($data,1)
assertErr(3,0,'Failed to read card data.')
; cardID out of bounds ( id<0 or id>Last index)
_fsOpenDecks($test_fsArrTestDecks)
_fsGetCardById($data,-2)
assertErr(4,0,'cardID out of bounds.')
_fsGetCardById($data,10)
assertErr(4,0,'cardID out of bounds.')
errSupress($errS)
; Test functionality
_fsGetCardById($data, 3)
assert(IsArray($data), 'Returned reference is not an array?.')
assert($data[2][0] = 'question', 'Expected keyname question, got ' & $data[2][0])
assert($data[2][1] = 'The capitol of Norway is named?', 'Expected: The capitol of Norway is named? But got ' & $data[2][1])
_fsCloseDecks()
EndFunc
Func test__fsGetQuizType()
Local $quizData[4][2] = [[3,0], ['CardType','text'], ['question', 'Can you ride on a horse?'], ['answer', '[yes]|[you can]|[ofcource]']]
Local $ret = __fsGetQuizType($quizData)
assert($ret = 'text', 'Unexpected quiz type return. Expected text got' & $ret)
Local $quizData2[4][2] =[[3,0],[0,0],[0,0],[0,0]]; [[3,0],['0','0'],['0','0'],['0','0']]; [[3,0],[1,2],[3,4],[5,6]]
$ret = __fsGetQuizType($quizData2)
assertErr(2,0,'Uhh, no error? $ret:=' & $ret)
Local $quizData3 = 3
$ret = __fsGetQuizType($quizData3)
assertErr(1,0,'Uhh, no error? $ret:=' & $ret)
EndFunc
Func test_fsOpenDecks()
;_fsOpenDecks($deckNames, $deckMode=0)
; $deckNames is a | delimited list of pathnames (or ID) to ini(later on z7) files containing a deck.
; Check for error when deck does not exist.
Local $errS = errSupress('',true)
Local $dbgS = dbgSupress('',true)
dbg('NOTE: testing error conditions so expect error messages.')
_fsOpenDecks('nonexistsingdeck.ini')
assertErr(@error = 1 AND @extended = 0, '_fsOpendeck(...) should return error01 as deck does not exists')
testCreateTestDeckAndData($test_fsGetCurrentDeck)
assert(FileExists($test_fsGetCurrentDeck), 'FileExists(' & $test_fsGetCurrentDeck & ') Should have returned true')
; Expect errors as some of the decks does not exist
_fsOpenDecks($test_fsGetCurrentDeck & '|nonexistsingdeck.ini|Anothernonexistsingdeck.ini')
assertErr(1, 2 , 'Some of the $deckNmaes entries could not be located @error:=' & @error & ', @extended:=' & @extended)
_fsOpenDecks('nonexistsingdeck.ini|' & $test_fsGetCurrentDeck & '|Anothernonexistsingdeck.ini')
assertErr(1 ,1 , 'Some of the $deckNmaes entries could not be located')
dbg('NOTE: Done testing error conditions')
errSupress('', $errS)
dbgSupress('', $dbgS)
_fsOpenDecks($test_fsGetCurrentDeck)
assert(@error=0, 'Expected @error to be 0 as ' & $test_fsgetCurrentDeck & ' should exist')
assert(FileDelete($test_fsGetCurrentDeck))
; Check for error when deck in list does not exsist.
; Check agains existing decks
Local $i, $s
For $i = 1 to $test_fsArrtestDecks[0]
$s &= $test_fsArrtestDecks[$i] & '|'
Next
StringTrimRight($s, StringLen('|'))
assert(_fsOpenDecks($s), '_fsOpenDecks should return true. decks:=' & $s)
_fsCloseDecks()
; TODO: Probably need more tests to cover everything
;assert(false, 'TODO: test_fsOpenDecks(...) Need more tests (diffrent deck modes) to check all conditions')
_fsCloseDecks()
EndFunc
Func test_fsShufleDecks()
; If several decks are provided in _fsOpenDecks then set current deck to use
; If _fsOpenDecks has not been called return error.
; Test agains empty list
Local $errS = errSupress('', true)
assert((False = _fsOpenDecks('')), 'Expected _fsOpenDecks(...) to return false and @error=1')
assertErr(1,0,'Expected @error=1 and @extended=0')
assert(0=_fsShufleDecks(), 'Expected 0 from _fsShufleDecks()')
assertErr(1,0, 'Expected _fsShufleDecks() to return error')
errSupress('',$errS)
; Test against one file in list
assert(_fsOpenDecks($test_fsArrtestDecks[1]), 'Expected _fsOpenDecks(...) to return true')
assert($test_fsArrtestDecks[1] = _fsShufleDecks(), 'Unexpected return ' & _fsShufleDecks() & ' <> ' & $test_fsArrtestDecks[1] )
; test against several filenames in list
assert(IsArray($test_fsArrtestDecks), 'Expected $test_fsArrtestDecks to be an array')
assert(_fsOpenDecks($test_fsArrtestDecks), 'Expected _fsOpenDecks(...) to return true')
Local $foo = _fsShufleDecks()
assert(IsString ($foo), 'Expected String got: ' & $foo )
assert(0 < StringinStr($test_TestDecks, $foo), 'Expected ' & $foo & ' to be in ' & $test_TestDecks )
_fsCloseDecks()
; TODO:
;assert(false, 'TODO: test_fsShufleDecks Need more tests (diffrent deck modes) to check all modes')
_fsCloseDecks()
EndFunc
Func test_fsGetCurrentDeck()
; Return current deck pathname (or ID)
assert(_fsOpenDecks($test_fsArrtestDecks), 'Expected _fsOpenDecks(...) to return true')
Local $foo = _fsGetCurrentDeck()
assert(StringInStr($test_TestDecks, $foo ), '_fsGetCurrentDeck()=' & $foo & ' returned unexpected result compared to $test_TestDecks:=' & $test_TestDecks)
assert($foo = _fsGetCurrentDeck(), '_fsGetCurrentDeck() should return the same in each successive call without call to _fsShufleDecks()')
_fsCloseDecks()
_fsCloseDecks()
EndFunc
Func test_fsSetCurrentDeck()
Local $foo
assert(_fsOpenDecks($test_fsArrtestDecks), 'Expected _fsOpenDecks(...) to return true')
$foo = _fsSetCurrentDeck(0)
assertErr(2, 0, '_fsSetCurrentDeck(0) should return @error=2, @extended=0')
assert($foo = _fsGetCurrentDeck(), 'Expect _fsSetCurrentDeck(0):=' & $foo & ' to return the same as _fsGetCurrentDeck():=' & _fsGetCurrentDeck())
;
$foo = _fsSetCurrentDeck(10)
assertErr(2, 3, '_fsSetCurrentDeck(0) should return @error=2, @extended=3 (number of files in list')
assert($foo = _fsGetCurrentDeck(), 'Expect _fsSetCurrentDeck(0):=' & $foo & ' to return the same as _fsGetCurrentDeck():=' & _fsGetCurrentDeck())
;
$foo = _fsSetCurrentDeck(2)
assertErr(0, 0, '_fsSetCurrentDeck(0) should return @error=2, @extended=3 (number of files in list')
assert($foo = 'testDeck2.ini', 'Expected _fsSetCurrentDeck(2) to return testDeck2.ini')
assert($foo = _fsGetCurrentDeck(), 'Expect _fsSetCurrentDeck(2):=' & $foo & ' to return the same as _fsGetCurrentDeck():=' & _fsGetCurrentDeck())
_fsCloseDecks()
_fsCloseDecks()
EndFunc
Func test___fsStringBracketClose()
Local $s = __fsStringBracketClose('test brackets')
assert(($s == '[test brackets]'), '__fsStringBracketClose():=' & $s)
$s = __fsStringBracketClose('[test brackets')
assert($s == '[test brackets]', '__fsStringBracketClose():=' & $s)
$s = __fsStringBracketClose('test brackets]')
assert($s == '[test brackets]', '__fsStringBracketClose():=' & $s)
EndFunc
;----------------------------------------------------------------------
; call test suite
If StringLeft(@ScriptName, StringLen(@scriptname)-4) == 'au3FlashCardsTest' Then suite_au3FlashCardstest()oÝ÷ Ù·[Ú(Æ®ßöÚºÚ"µÍÚ[ÛYK[ÛÙBÛØ[ ÌÍÙÝÛÛÐÜÙØ[ÛÝ[HÛØ[ ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[HÛØ[ ÌÍÙÝÛÛÑÝÜÈH[ÙBÛØ[ ÌÍÙÝÛÛÑÔÝÜÈH[ÙB[ÈÝÜÊ ÌÍÛÙÏIÌÎNÉÌÎNË ÌÍÜÚ[[KLJBNÈYØ[YÚ]Ý] ÌÍÜÚ[Ù[ÙÛHYKÙ[ÙBSØØ[ ÌÍÜ]H ÌÍÙÝÛÛÑÝÜÂRY ÌÍÜÚ[[OHLH[BIÌÍÙÝÛÛÑÝÜÈHÕ ÌÍÙÝÛÛÑÝÜÂQ[ÙBBIÌÍÙÝÛÛÑÝÜÈHÕÕ ÌÍÜÚ[[Q[YT] ÌÍÜ][[Â[ÈÔÝÜÊ ÌÍÛÙÏIÌÎNÉÌÎNË ÌÍÜÚ[[KLJBNÈYØ[YÚ]Ý] ÌÍÜÚ[Ù[ÙÛHYKÙ[ÙBSØØ[ ÌÍÜ]H ÌÍÙÝÛÛÑÔÝÜÂRY ÌÍÜÚ[[OHLH[BIÌÍÙÝÛÛÑÔÝÜÈHÕ ÌÍÙÝÛÛÑÔÝÜÂQ[ÙBBIÌÍÙÝÛÛÑÔÝÜÈHÕÕ ÌÍÜÚ[[Q[YT] ÌÍÜ][[Â[È ÌÍÛÙË ÌÍÛ[OPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y
BZY ÌÍÙ ÝÈ[BRYÝ ÌÍÙÝÛÛÑÝÜÈ[Ê ÌÎNÑTÔ ÌÎNÈ [È ÌÍÛÙË ÌÍÛ[K ÌÍÙ ÌÍÙ^
BBT]Ù]Ü ÌÍÙ ÌÍÙ^YJBQ[ÙRY ÌÍÙ^ ÝÈ[BRYÝ ÌÍÙÝÛÛÑÝÜÈ[Ê ÌÎNÑVSQ ÌÎNÈ [È ÌÍÛÙË ÌÍÛ[K ÌÍÙ ÌÍÙ^
BBT]Ù]^[Y
ÌÍÙ^YJBQ[YT][ÙB[[Â[ÈÊ ÌÍÛÙË ÌÍÛ[OPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y ÌÍÜOIÌÎNÉÌÎNË ÌÍÙÑÜÙHH
BRY ÌÍÙÑÜÙHOH[ ÌÍÙÑÜÙHHÕ ÌÍÙÝÛÛÑÔÝÜÂRY ÌÍÙÑÜÙH[BSØØ[ ÌÍÛÝ]H ÌÍÜH [È ÌÎNÊ ÌÎNÈ [È ÌÍÛ[H [È ÌÎNÊH
ÌÎNÈ [È ÌÍÙ [È ÌÎNÊJ ÌÎNÈ [È ÌÍÙ^ [È ÌÎNÊH ÌÎNÈ [È ÌÍÛÙÈBRYÝÛÛ[YSØÙÜÑ^ÝÊ ÌÎNÔØÚUK^IÌÎNÊH[BBPÛÛÛÛUÜ]J ÌÍÛÝ] [ÈÔBBQ[ÙBBBQØ[
][ÝÚÙ[Ì ][ÝË ][ÝÛÛI][ÝË ][ÝÓÝ]]XYÔÝ[É][ÝË ][ÝÜÝ][ÝË ÌÍÛÝ]
BBQ[YQ[Y[[Â[ÈÐ ÌÍØ ÌÍÛ[HPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y
BYÊ ][ÝÐTVHSTÕTXÝ[I][ÝÈ [ÈPÝ[
ÌÍØK ÌÍÛ[K ÌÍÙ ÌÍÙ^
BSØØ[ ÌÍÚBQÜ ÌÍÚHHÈPÝ[
ÌÍØKLBBRYÝ[ÓY
ÌÍØÉÌÍÚWKJHOH ][ÝÊ ][ÝÈ[BBYÊ ÌÍØÉÌÍÚWH [È ][ÝÈ ÉÏOIÌÍØÉ][ÝÈ [È ÌÍÚH [È ][Ý×I][ÝÈ ÌÍÛ[K ÌÍÙ ÌÍÙ^
BBQ[ÙBBBYÊ ][ÝÉÌÍØÉ][ÝÈ [È ÌÍÚH [È ][Ý×NI][ÝÈ [È ÌÍØÉÌÍÚWK ÌÍÛ[K ÌÍÙ ÌÍÙ^
BBQ[YS^YÊ ][ÝÐTVHSTÓN][ÝË ÌÍÛ[K ÌÍÙ ÌÍÙ^
B[[Â[ÈÜÙ
ÌÍØÛÛ ÌÍÛÙÏI][ÝÉ][ÝË ÌÍÛ[OPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y
BIÌÍÙÝÛÛÐÜÙØ[ÛÝ[
ÏHBRY ÌÍØÛÛ[ ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[
ÏHBRYÝ ÌÍØÛÛ[Ê ÌÎNÐTÔÑTRSQ ÌÎNÈ [È ÌÍÛÙË ÌÍÛ[K ÌÍÙ ÌÍÙ^ ÌÎNÉÌÎNËYJBNÔ]Ù]Ü ÌÍÙ ÌÍÙ^[X ÌÍØÛÛ
JBT]Ù]Ü ÌÍÙ ÌÍÙ^ ÌÍØÛÛ
B[[Â[ÈÜÙ ÌÍÙ^XÝY ÌÍÙ^XÝY^H ÌÍÛÙÏIÌÎNÉÌÎNË ÌÍÛ[OPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y
BIÌÍÙÝÛÛÐÜÙØ[ÛÝ[
ÏHBRY ÌÍÙ ÉÝÈ ÌÍÙ^XÝYÔ ÌÍÙ^ ÉÝÈ ÌÍÙ^XÝY^[BYÊ ÌÎNÐTÔÑTÑTRSQ
ÌÎNÉ[ÉÌÍÙ^XÝY [ÉÌÎNÉÉÝÉÌÎNÈ [È ÌÍÙ [ÉÌÎNÊJ ÌÎNÈ [ÉÌÍÙ^XÝY^ [ÉÌÎNÉÉÝÉÌÎNÈ [È ÌÍÙ^ [ÉÌÎNÊIÌÎNÈ [È ÌÍÛÙË ÌÍÛ[K ÌÍÙ ÌÍÙ^ ÌÎNÉÌÎNËYJBQ[ÙBBIÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[
ÏHBQ[YT]Ù]Ü ÌÍÙ ÌÍÙ^
ÌÍÙIÌÍÙ^XÝY[ ÌÍÙ^IÌÍÙ^XÝY^
JB[[È[ÈÜÙÜ
ÌÍØØ[XÚÏI][ÝÉ][ÝÊBRY ÌÍØØ[XÚÈ ÉÝÈ ][ÝÉ][ÝÈ[BYÊ ÌÎNÉÌÍØØ[XÚÎIÌÎNÈ [È ÌÍØØ[XÚÊBBNÈØ[XÚÈÒQÓUTN Ù[Ý[Û[YIÝÊ ÌÍÜÝXÙÜË ÌÍÙZ[K ÌÍØÛÝ[
BBPØ[
ÌÍØØ[XÚË ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[ ÌÍÙÝÛÛÐÜÙØ[ÛÝ[H ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[ ÌÍÙÝÛÛÐÜÙØ[ÛÝ[
BQ[ÙBBYÊ ÌÎNËKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKIÌÎNÊBBYÊ ÌÎNÔÝXÙÜÎIÌÎNÈ [È ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[ [È ÌÎNËZ[ÎIÌÎNÈ [È ÌÍÙÝÛÛÐÜÙØ[ÛÝ[H ÌÍÙÝÛÛÐÜÙÝXØÙÜÐÛÝ[ [È ÌÎNËØ[ÎIÌÎNÈ [È ÌÍÙÝÛÛÐÜÙØ[ÛÝ[
BBYÊ ÌÎNËKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKIÌÎNÊBQ[Y[[Â[ÈÜÙÐÛÙJ ÌÍÛÙÏIÌÎNÓÈÓÑIÌÎNË ÌÍÛ[OPØÜ[S[X ÌÍÙPÜ ÌÍÙ^P^[Y
BXÜÙ
[ÙK ÌÍÛÙË ÌÍÛ[K ÌÍÙ ÌÍÙ^
B[[Â[ÈÝZ]WÙÝÛÛÊ
BNÝÝÙÊ
B]ÝÙ
BNÝÝÙÐ
BNÝÝØÜÙ
B]ÝØÜÙ
B[[Â[ÈÝÙÊ
BYÊ ÌÎNÙ^XÝÈ[H[ÕY]ÈÜØÚUHÛÛÛÛHÚ[ÝË[HHÝXHÛXÚÚ[ÉÌÎNÊB[[Â[
ÈÙÊ ÌÍÛÙÏIÌÎNÉÌÎNË ÌÍÛ[OPØÜ[S[XBYÊ ÌÎNÕÑÎ ÌÎNÈ [È ÌÍÛÙË ÌÍÛ[JB[[Â[ÈÝØÜÙ
BRYÝÜÙ
YK ÌÎNÕZ[^XÝYÝ[ ÌÎNÊH[Ê ÌÎNÕSVPÕQÜÙZ[YÈ]HHYÚ[YIÌÎNÊB[[Â[ÈÝØÜÙ
BXÜÙK ÌÎNÑ^XÝÝ]]ÛHÈ[IÌÎNËØÜ[S[XK
BXÜÙKË ÌÎNÑ^XÝÝ]]ÛHÈ[IÌÎNËØÜ[S[XKÊB[[Â[ÈÝÙÐ
BSØØ[ ÌÍØÍHHÌË ÌÎNÚ][LIÌÎNË ÌÎNÚ][LÌÎNË ÌÎNÚ][LÉÌÎN×BYÐ ÌÍØB[[Â[È×ÙØYÙJ ÌÍÙ ÌÍÙ^ ÌÍÛ[OPØÜ[S[XBNÝXØ[ØYÙHÙHRY ÌÎN××ÙØYÙNÚ]HÜX]HÜYÜØYÙIÌÎNË ÌÍÛ[K ÌÍÙ ÌÍÙ^
H[]Ù]ÜÜ^[Y[ÙJBNÈÙHÚÝ[ÝÙ]ÈÈ[HY ÌÍÙÜ ÌÍÙ^È ÝÈBT]ÜÙ
ÌÍÙLS ÌÍÙ^L ÌÎNÕZÚÝ[ÝÙ]H[ÜÈÝH ÌÍÙIÌÎNÈ [È ÌÍÙ [È ÌÎNË ÌÍÙ^IÌÎNÈ [È ÌÍÙ^
B[[Â[ÈÝÙ
BSØØ[ ÌÍØÜÙÛÝ[HYÝÜÊ
HÕÙÜÜÂTÙ]ÜK
BXÜÙ
ÌÎNÑ^XÝYÜÝÌÚÝ[XZÙH]YK[Ü]HÈÈHÙÉÌÎNÊK ÌÎNÑÛÝ[^XÝY[ÙHÛHIÌÎNÊBTÙ]ÜJBXÜÙ
ÌÎNÑ^XÝYÜÙY^[YXZÙÈ]YK^XÝVSQ[ÙËÌÎNÊK ÌÎNÑÛÝ[^XÝY[ÙHÛHIÌÎNÊBTÙ]^[Y
BXÜÙ
[ÙHH ÌÎNÙÜL[^[YLÚÝ[XZÙH]H[ÙIÌÎNÊK ÌÎNÑÛÝ[^XÝYYHÛHIÌÎNÊBBNÈÛÛYHØ^ÈÙØYÙKÜXÚX[H[ÝY[ ][ÝÛXÙHÜ[[[É][ÝÂBXÜÙ
×ÙØYÙJ
JBXÜÙ
Ý×ÙØYÙJK
K ÌÎNÔÚÝ[][ÙOÉÌÎNÊBXÜÙ
Ý×ÙØYÙJJK ÌÎNÔÚÝ[][ÙOÉÌÎNÊBXÜÙ
Ý×ÙØYÙJKJK ÌÎNÔÚÝ[][ÙOÉÌÎNÊBXÜÙ
×ÙØYÙJ
K ÌÎNÔÚÝ[]YOÉÌÎNÊBYÝÜÊ
HÕÛÜÜÂXÜÙÜ
B[[ÂYÝ[ÓY
ØÜ[YKÝ[Ó[ØÜ[YJKM
HOH ÌÎNÙÝÛÛÉÌÎNÈ[ÝZ]WÙÝÛÛÊ
B[Y