OSDN Git Service

こっそり、気持ち程度の日本語化しました (UTF-8 / Windows 環境用)。
[ring-lang-081/annotated-ring-with-OmegaT.git] / target / ringlibs / stdlib / test.ring
1 # Ring 標準ライブラリ
2 # アプリケーション用の汎用関数とクラス
3 # 2016, Mahmoud Fayed <msfclipper@yahoo.com>
4 # 2016, CalmoSoft <calmosoft@gmail.com>
5 Load "stdlib.ring"
6
7 # Application Path
8 Puts("AppPath() のテスト")
9 See AppPath() + nl
10
11 # Execute a function nCount of times
12 Puts("Times() のテスト")
13 Times ( 3 , func { see "Hello, World!" + nl } )
14
15 # Execute a function on each list item
16 Puts("Map() のテスト")
17 See Map( 1:10, func x { return x*x } )
18
19 # Test the Value function to copy a list or object
20 Puts("Value() のテスト")
21 See value(1:10)
22
23 # Test the Filter function
24 Puts("Filter() のテスト")
25 See Filter( 1:10 , func x { if x <= 5 return true else return false ok } )
26
27 # Test the Split function
28 Puts("Split() のテスト")
29 See Split("one two three four five"," ")
30
31 # Test the Newlist function
32 Puts("Newlist() のテスト")
33 a1 = 3
34 a2 = 5
35 chrArray = newlist(a1,a2)
36 numArray = newlist(a1,a2)
37 chrArray[1][1] = "Hello"
38 numArray[1][1]  = 987.2
39 See chrArray[1][1] + nl
40 See numArray[1][1] + nl
41
42 # Return a copy with the first letter capitalized
43 Puts("Capitalized() のテスト")
44 See capitalized("welcome to the Ring Programming Language")
45
46 # Test if the character is a special character?
47 Puts("Isspecial() のテスト")
48 See "Isspecial  = " + isSpecial("%") + nl
49
50 # Test if the character is a vowel character?
51 Puts("Isvowel() のテスト")
52 See "Isvowel = " + isVowel("c") + nl
53
54 # Return the number of lines (lines count) in a text file
55 Puts("Linecount() のテスト")
56 See "the number of lines = " + lineCount("test.ring")
57
58 # Return the factorial of number
59 Puts("Factorial() のテスト")
60 see "6 factorial is : " + Factorial(6)
61
62 # Return the Fibonacci number
63 Puts("Fibonacci() のテスト")
64 see "6 Fibonacci is : " + Fibonacci(6)
65
66 # Check whether a number is prime or not
67 Puts("Isprime() のテスト")
68 flag = isPrime(16)
69 if flag = 1 see "16 is a prime number"
70 else see "16 is not a prime number" ok
71
72 # Returns an Integer value indicating the sign of a number.
73 Puts("Sign() のテスト")
74 see "sign of 12 is = " + sign(12) + nl
75
76 # Test List2File
77 Puts("List2File() のテスト")
78 list2file(1:100,"myfile.txt")
79
80 # Test File2List
81 Puts("File2List() のテスト")
82 see len(file2list("myfile.txt"))
83
84 # Returns true if the given string ends with the specified substring. Trailing white spaces are ignored.
85 Puts("Endswith() のテスト")
86 see endsWith("CalmoSoft", "Soft") + nl
87
88 # Returns true if the given string starts with the specified substring. Leading white spaces are ignored.
89 Puts("Startswith() のテスト")
90 see Startswith("CalmoSoft", "Calmo") + nl
91
92 # Finding of the greatest common divisor of two integers.
93 Puts("Gcd() のテスト")
94 see gcd (24, 32) + nl
95
96 # Compute the least common multiple of two integers.
97 Puts("Lcm() のテスト")
98 see Lcm(24,36) + nl
99
100 # Compute the product of a list of integers.
101 Puts("Prodlist() のテスト")
102 aList = [1,2,3,4,5]
103 see Prodlist(aList) + nl
104
105 # Compute the sum of a list of integers.
106 Puts("Sumlist() のテスト")
107 aList = [1,2,3,4,5]
108 see Sumlist(aList) + nl
109
110 # Compute the sum of a list of integers.
111 Puts("Evenorodd() のテスト")
112 nr = 17
113 see Evenorodd(nr) + nl
114
115 # Compute the factors of a positive integer.
116 Puts("Factors() のテスト")
117 n = 45
118 aList = factors(n)
119 see "Factors of " + n + " = "
120 for i = 1 to len(aList)
121     see "" + aList[i] + " "
122 next
123
124 # Check if a sequence of characters is a palindrome or not.
125 Puts("Palindrome() のテスト")
126 cString = "radar"
127 Palindrome(cString)
128
129 # Check whether a given year is a leap year in the Gregorian calendar.
130 Puts("Isleapyear() のテスト")
131 year = 2016
132 if Isleapyear(year) see "" + year + " is a leap year."
133 else see "" + year + " is not a leap year." ok
134
135 # Compute the sequence of binary digits for a given non-negative integer.
136 Puts("Binarydigits() のテスト")
137 b = 35
138 see "Binary digits of " + b + " = "
139 see Binarydigits(b) + nl
140
141 # Multiply two matrices together.
142 Puts("Matrixmulti() のテスト")
143 A = [[1,2,3], [4,5,6], [7,8,9]]
144 B = [[1,0,0], [0,1,0], [0,0,1]]
145 see Matrixmulti(A, B)
146
147 # Transpose an arbitrarily sized rectangular Matrix.
148 Puts("Matrixtrans() のテスト")
149 matrix = [[78,19,30,12,36], [49,10,65,42,50], [30,93,24,78,10], [39,68,27,64,29]]
150 see Matrixtrans(matrix)
151
152 # Return the day of the week of given date.
153 Puts("Dayofweek() のテスト")
154 date = "2016-04-24"
155 see "Data : " + date + " - Day : " + Dayofweek(date) + nl
156
157 # Friday the 13th between start and end year.
158 Puts("Fridays() のテスト")
159 year1 = 2010
160 year2 = 2020
161 Fridays(year1, year2)
162
163 # Generates all permutations of n different numerals
164 Puts("Permutation() のテスト")
165 list = [1, 2, 3, 4]
166 for perm = 1 to 24
167      for i = 1 to len(list)
168           see list[i] + " "
169      next
170      see nl
171      Permutation(list)
172 next
173
174
175 # Sleep for the given amount of time.
176 Puts("Sleep() のテスト")
177 see "Wait 3 Seconds!"
178 Sleep(3)
179 see nl
180
181 # Read a file line by line.
182 Puts("Readline() のテスト")
183 fp = fopen("test.ring","r")
184 while not feof(fp)
185 See Readline(fp) end
186 fclose(fp)
187
188 # Return a position of a substring starting from a given position in a string.
189 Puts("Substring() のテスト")
190 a = "abcxyzqweabc"
191 b = "abc"
192 i = 4
193 see substring(a,b,i)
194
195 # Change substring from given position for given position with a substring.
196 Puts("Changestring() のテスト")
197 see Changestring("Rmasdg",2,5,"in")
198
199 # Test print()
200 print("\nHello, World\n\nHow are you? \t\t I'm fine!\n")
201 x=10 y=20
202 print("\nx value = #{x} , y value = #{y} \n")
203
204 # Check directory
205 see "Check dir : b:\ring " 
206 puts( DirExists("b:\ring") )
207 see "Check dir : C:\ring " 
208 Puts( DirExists("C:\ring") )
209
210 # ディレクトリの作成
211 puts("ディレクトリの作成 : myfolder")
212 makedir("myfolder")
213
214 # GetString() and GetNumber() のテスト
215 See "Test getstring() and getnumber()"+nl
216 See "Enter your name ?" 
217 cName = getstring()
218 see "Your name is : " + cName + nl
219 See "Enter your Age? "
220 nAge = getnumber()
221 nAge++
222 See "Your age after 1 year : " + nAge + nl
223
224 # Sort a two-dimensional list on the first index.
225 Puts("sortFirstSecond() のテスト")
226 aList = [[2,2], [1,2], [3,2], [3,1], [1,1]]
227 sortFirstSecond(aList, 1)
228
229 for n=1 to len(aList)
230     for m=1 to 2
231         see string(aList[n][m]) + " "
232     next
233     see nl
234 next
235
236 # Sort a two-dimensional list on the second index.
237 Puts("sortFirstSecond() のテスト")
238 aList = [[2,2], [1,2], [3,2], [3,1], [1,1]]
239 sortFirstSecond(aList, 2)
240
241 for n=1 to len(aList)
242     for m=1 to 2
243         see string(aList[n][m]) + " "
244     next
245     see nl
246 next
247
248 # メインソースファイルのテスト
249 see "IsMainSourceFile() : " + ismainsourcefile() + nl
250 See "Previous File Name : " + PrevFileName() + nl
251 see "IsMainSourceFile() : " + ismainsourcefile() + nl
252