Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
154 lines (142 sloc) 3.78 KB
#testing out some basic string stuff#
fun teststrings
{
#A basic Hello World#
mystring = "Hello World";
print mystring;
mystring2 = mystring / "l"; #string splitting!#
print mystring2; #should print ['He', '', 'o Wor', 'd']#
print mystring[6]; #should print "W"#
mystring[6] = "B"; #wow you can assign to parts of a string!#
print mystring; #should print "Hello Borld"#
mynum = 6;
mystring = mystring + mynum;
print mystring; #should print "Hello Borld6.0"#
myword = "cat";
mysentence = "I want a {myword}";
print mysentence; #should print "I want a cat"#
mysentence = mysentence - "want ";
print mysentence; #should print "I a cat"#
print len(mysentence); #should print 7.0#
}
#testing conditionals#
fun testconditionals
{
x = 3;
y = 5;
if (y >= x)
then
{
print "correct!"; #this should be printed#
}
else
{
print "incorrect!"; #this should not be printed#
};
if (y!=x)
then
{
print "correct!"; #this should be printed#
}
else
{
print "incorrect!"; #this should not be printed#
};
}
#testing passing arguments to and from functions#
fun testfunctions
{
print "this was passed " + argv; #should print "this was passed myarg"#
mystring = "x from the previous function = " + x;
print mystring; #should print "x from the previous function = 3.0"#
i = 2;
j = 5;
k = i^j;
result = "the result is: " + k;
return result;
}
#testing some array things#
fun testarrays
{
myarray1 = [3,5];
myarray2 = myarray1 + 2;
print myarray2; #should print [5.0, 7.0]#
myarray1 = myarray1 * 2;
myarray3 = myarray1 . myarray2;
print myarray3; #should print [6.0, 10.0, 5.0, 7.0]#
myarray4 = myarray2 . 3.8;
print myarray4; #should print [5.0, 7.0, 3.8]#
myarray5 = [4,"four",[-6,2]];
print myarray5; #should print [4.0, 'four', [-6.0, 2.0]]#
print len(myarray5); #should print 3.0#
}
#looops loops loops loops#
fun testloops
{
print "loops!";
x = 0;
while (x < 10)
then {
x = x + 1;
print x; #should print the numbers 1 to 10#
};
print "yay!";
}
#testing file reading/writing#
fun testfileio
{
myvar = "hello filesystem!";
filename = fileloc + "myfile.txt";
fileout(filename)(myvar);
print filename; #should print the path to myfile.txt in the same directory as this file#
myresult = filein(filename);
print myresult; #should print "hello filesystem!"#
urlname = "http://willow.lol/test.txt";
myresult = filein(urlname); #you can read from URLs too!#
print myresult; #should print "Hello Internet!"#
}
#testing random number generation#
fun testrandom
{
mynum = random(1);
print mynum; #should print a float between 0 and 1#
mynum = random(10);
print mynum; #should print a float between 0 and 10#
mynum = random(100);
print floor(mynum); #should print a whole number between 0 and 100#
if (random(10) > 5)
then{
print "bigger!"; #this might print#
}
else{
print "smaller..."; #or this might print#
}
}
#testing command-line input#
fun testinput
{
mystring = "what is your name? ";
myresult = prompt(mystring);
mysentence = "hello, " + myresult;
print mysentence; #should print "hello, willow" if you entered willow#
mynum = prompt("give me a number: ");
x = mynum + 2;
mysentence = mynum+ " + 2.0 = " + x;
print mysentence; #should print "5.0 + 2.0 = 7.0" if you enter 5#
}
#the main function#
fun main
{
print "arguments: " + argv; #should print any command line arguments#
call(teststrings);
call(testconditionals); #you can call a function directly by name#
myfunc = "testfunctions";
z = call(myfunc)("myarg"); #or by passing in a variable that holds a function name#
print z; #should print "the result is: 32.0"#
call(testarrays);
call(testloops);
call(testfileio);
call(testrandom);
print call(notafunction) #should print 0.0#
#call(testinput);#
}