-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests.oi
78 lines (66 loc) · 1.71 KB
/
tests.oi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Work with strings
substrings = std._version.split("\\.")
major = int(substrings[0])
minor = int(substrings[1])
patch = int(substrings[2])
print(major, minor, patch)
print("test ".count(""))
print("".count("ab"))
print("absolute abc".count("ab"))
# Power
value = 3
power = 3
result = 1
for i : power:
result *= value
print(result)
# This code
for i : 1 to 10:
for j : 1 to 10:
if i * j < 10:
_print " "
_print i * j
_print " "
print()
# Outputs:
# 1 2 3 4 5 6 7 8 9 10
# 2 4 6 8 10 12 14 16 18 20
# 3 6 9 12 15 18 21 24 27 30
# 4 8 12 16 20 24 28 32 36 40
# 5 10 15 20 25 30 35 40 45 50
# 6 12 18 24 30 36 42 48 54 60
# 7 14 21 28 35 42 49 56 63 70
# 8 16 24 32 40 48 56 64 72 80
# 9 18 27 36 45 54 63 72 81 90
#10 20 30 40 50 60 70 80 90 100
include math
func quadratic_equation(a, b, c):
d = b*b - 4*a*c
if d < 0.0:
return []
elif d == 0.0:
return [(-b)/(2*a)]
else:
rd = sqrt(d)
x1 = (-b - rd)/(2*a)
x2 = (-b + rd)/(2*a)
return [x1, x2]
print(quadratic_equation(1, 2, -3))
func tostr(self):
return "User(name: "+cat(self.name)+", age: "+self.age+")"
func User_init(self, name, age):
self.name = name
self.age = age
# define prototype User
User = {"_init": User_init, "_str": tostr}
# define object that use User as prototype
# using default $new(...) implementation
print(new User("unknown", 45)._str())
func custom_new(prototype, *args):
obj = {"_proto": prototype}
obj._init(*args)
print("CUSTOM NEW USED with prototype", prototype, "args:", args)
return obj
script._included["$new"] = custom_new
# using user-defined $new(...) implementation
print(new User("Tester", 90)._str())