proc runTest { testDir testFile } {
    global argc argv

    set saveDir [pwd]
    cd $testDir

    if { $::tcl_platform(platform) eq "windows" } {
        set tclsh "tclsh.exe"
    } else {
        set tclsh "tclsh"
    }
    puts "Running test $testFile ..."
    catch {exec $tclsh $testFile}

    cd $saveDir
}

proc getTestName { num } {
    return [format "Lesson%02d" $num]
}

set testList { 
    1  2  3  4  5  6  7  8  9 10 
   11 12 13 14    16    18 19 20
   21 22 23 24 25 26 27 28      
      32 33    35 36 37       
   41          45 46    48 
}

set start [lindex $testList 0]
set end   [lindex $testList end]

if { $argc == 1 } {
    set start [lindex $argv 0]
    set end   [lindex $argv 0]
} elseif { $argc > 1 } {
    set start [lindex $argv 0]
    set end   [lindex $argv 1]
}

foreach testNum $testList {
    if { $testNum >= $start && $testNum <= $end } {
        set testName [getTestName $testNum]
        runTest $testName "$testName.tcl"
    }
}
