Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,35 @@
public class Compare
{
/**
* Test in the developer console:
* Compare.compare('Hello', 'Hello');
* Compare.compare('5', '5.0');
* Compare.compare('java', 'Java');
* Compare.compare('ĴÃVÁ', 'ĴÃVÁ');
*/
public static void compare (String A, String B)
{
if (A.equals(B))
System.debug(A + ' and ' + B + ' are lexically equal.');
else
System.debug(A + ' and ' + B + ' are not lexically equal.');
if (A.equalsIgnoreCase(B))
System.debug(A + ' and ' + B + ' are case-insensitive lexically equal.');
else
System.debug(A + ' and ' + B + ' are not case-insensitive lexically equal.');
if (A.compareTo(B) < 0)
System.debug(A + ' is lexically before ' + B);
else if (A.compareTo(B) > 0)
System.debug(A + ' is lexically after ' + B);
if (A.compareTo(B) >= 0)
System.debug(A + ' is not lexically before ' + B);
if (A.compareTo(B) <= 0)
System.debug(A + ' is not lexically after ' + B);
System.debug('The lexical relationship is: ' + A.compareTo(B));
}
}

View file

@ -0,0 +1,40 @@
' FB 1.05.0
' Strings in FB natively support the relational operators which compare lexically on a case-sensitive basis.
' There are no special provisions for numerical strings.
' There are no other types of string comparison for the built-in types though 'user defined types'
' can specify their own comparisons by over-loading the relational operators.
Function StringCompare(s1 As Const String, s2 As Const String, ignoreCase As Boolean = false) As String
Dim As String s, t ' need new string variables as the strings passed in can't be changed
If ignoreCase Then
s = LCase(s1)
t = LCase(s2)
Else
s = s1
t = s2
End If
If s < t Then Return " comes before "
If s = t Then Return " is equal to "
Return " comes after "
End Function
Dim As Integer result
Dim As String s1, s2, s3
s1 = "Dog" : s2 = "Dog"
Print s1; StringCompare(s1, s2); s2
s2 = "Cat"
Print s1; StringCompare(s1, s2); s2
s2 = "Rat"
Print s1; StringCompare(s1, s2); s2
s2 = "dog"
Print s1; StringCompare(s1, s2); s2
Print s1; StringCompare(s1, s2, True); s2; " if case is ignored"
s1 = "Dog" : s2 = "Pig"
s3 = StringCompare(s1, s2)
If s3 <> " is equal to " Then
Print s1; " is not equal to "; s2
End If
Print
Print "Press any key to quit"
Sleep

View file

@ -0,0 +1,12 @@
IF s1 == s2
? "The strings are equal"
ENDIF
IF !( s1 == s2 )
? "The strings are not equal"
ENDIF
IF s1 > s2
? "s2 is lexically ordered before than s1"
ENDIF
IF s1 < s2
? "s2 is lexically ordered after than s1"
ENDIF

View file

@ -0,0 +1,3 @@
IF Upper( s1 ) == Upper( s2 )
? "The strings are equal"
ENDIF

View file

@ -0,0 +1,35 @@
// Comparing two strings for exact equality
"'this' == 'this': " + ('this' == 'this') // true
"'this' == 'This': " + ('this' == 'This') // true, as it's case insensitive
// Comparing two strings for inequality (i.e., the inverse of exact equality)
"'this' != 'this': " + ('this' != 'this')// false
"'this' != 'that': " + ('this' != 'that') // true
// Comparing two strings to see if one is lexically ordered before than the other
"'alpha' < 'beta': " + ('alpha' < 'beta') // true
"'beta' < 'alpha': " + ('beta' < 'alpha') // false
// Comparing two strings to see if one is lexically ordered after than the other
"'alpha' > 'beta': " + ('alpha' > 'beta') // false
"'beta' > 'alpha': " + ('beta' > 'alpha') // true
// How to achieve both case sensitive comparisons and case insensitive comparisons within the language
"case sensitive - 'this'->equals('This',-case=true): " + ('this'->equals('This',-case=true)) // false
"case insensitive - 'this'->equals('This',-case=true): " + ('this'->equals('This')) // true
// How the language handles comparison of numeric strings if these are not treated lexically
"'01234' == '01234': "+ ('01234' == '01234') // true
"'01234' == '0123': " + ('01234' == '0123') // false
"'01234' > '0123': " + ('01234' > '0123') // true
"'01234' < '0123': " + ('01234' < '0123') //false
// Additional string comparisons
"'The quick brown fox jumps over the rhino' >> 'fox' (contains): " +
('The quick brown fox jumps over the rhino' >> 'fox') // true
"'The quick brown fox jumps over the rhino' >> 'cat' (contains): " +
('The quick brown fox jumps over the rhino' >> 'cat') // false
"'The quick brown fox jumps over the rhino'->beginswith('rhino'): " +
('The quick brown fox jumps over the rhino'->beginswith('rhino')) // false
"'The quick brown fox jumps over the rhino'->endswith('rhino'): " +
('The quick brown fox jumps over the rhino'->endswith('rhino')) // true

View file

@ -0,0 +1,11 @@
put "abc"="ABC"
-- 1
put "abc"<>"def"
-- 1
put "abc"<"def"
-- 1
put "abc">"def"
-- 0

View file

@ -0,0 +1,10 @@
-- Returns -1 if str1 is less than str2
-- Returns 1 if str1 is greater than str2
-- Returns 0 if str1 and str2 are equal
on strcmp (str1, str2)
h1 = bytearray(str1).toHexString(1, str1.length)
h2 = bytearray(str2).toHexString(1, str2.length)
if h1<h2 then return -1
else if h1>h2 then return 1
return 0
end

View file

@ -0,0 +1,10 @@
import strutils
var s1: string = "The quick brown"
var s2: string = "The Quick Brown"
echo("== : ", s1 == s2)
echo("!= : ", s1 != s2)
echo("< : ", s1 < s2)
echo("<= : ", s1 <= s2)
echo("> : ", s1 > s2)
echo(">= : ", s1 >= s2)

View file

@ -0,0 +1,5 @@
"abcd" "abcd" ==
"abcd" "abce" <>
"abcd" "abceed" <=
"abce" "abcd" >
"abcEEE" toUpper "ABCeee" toUpper ==

View file

@ -0,0 +1,6 @@
if name=="pete" then ?"The strings are equal" end if
if name!="pete" then ?"The strings are not equal" end if
if name<"pete" then ?"name is lexically first" end if
if name>"pete" then ?"name is lexically last" end if
if upper(name)=upper("pete") then ?"case insensitive match" end if
if match("pete",lower(name)) then ?"petes in there somewhere" end if

View file

@ -0,0 +1,18 @@
if s1 = s2
See "The strings are equal"
ok
if not (s1 = s2)
See "The strings are not equal"
ok
if strcmp(s1,s2) > 0
see "s2 is lexically ordered before than s1"
ok
if strcmp(s1,s2) < 0
see "s2 is lexically ordered after than s1"
ok
To achieve case insensitive comparisons, we should use Upper() or Lower() functions:
if Upper(s1) = Upper(s2)
see "The strings are equal"
ok

View file

@ -0,0 +1,5 @@
var methods = %w(== != > >= < <= <=>)
for s1, s2 in [<YUP YUP>,<YUP Yup>,<bot bat>,<aaa zz>] {
methods.each{|m| "%s %s %s\t%s\n".printf(s1, m, s2, s1.(m)(s2))}
print "\n"
}

View file

@ -0,0 +1,23 @@
func compare (a: String, b: String) {
if a == b {
println("'\(a)' and '\(b)' are lexically equal.")
}
if a != b {
println("'\(a)' and '\(b)' are not lexically equal.")
}
if a < b {
println("'\(a)' is lexically before '\(b)'.")
}
if a > b {
println("'\(a)' is lexically after '\(b)'.")
}
if a >= b {
println("'\(a)' is not lexically before '\(b)'.")
}
if a <= b {
println("'\(a)' is not lexically after '\(b)'.")
}
}
compare("cat", "dog")

View file

@ -0,0 +1,11 @@
# Comparing two strings for exact equality:
"this" == "this" # true
"this" == "This" # false
# != is the inverse of ==
# Comparing two strings to see if one is lexically ordered before the other:
"alpha" < "beta" # true
"beta" < "alpha" # false
# > is the inverse of <

View file

@ -0,0 +1,7 @@
# Only characters A to Z are affected
def downcase:
explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode;
# Only characters a to z are affected
def upcase:
explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode;

View file

@ -0,0 +1 @@
("AtoZ" | upcase) == ("atoz" | upcase) # true