Skip to content

Commit e7df5ea

Browse files
committed
update to latest jule version
1 parent ffd6910 commit e7df5ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+353
-356
lines changed

math/abs.jule

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn Abs(mut n: f64): f64 {
2-
if n < 0 {
3-
n = -n
4-
}
5-
ret n
2+
if n < 0 {
3+
n = -n
4+
}
5+
ret n
66
}

math/abs_test.jule

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testAbs(t: &testing::T) {
7-
t.Assert(Abs(-12.2) == 12.2, "-12.2 should equal to 12.2")
8-
t.Assert(Abs(-12) == 12, "-12 should equal to 12")
9-
t.Assert(Abs(-0.35) == 0.35, "-0.35 should equal to 0.35")
10-
}
7+
t.Assert(Abs(-12.2) == 12.2, "-12.2 should equal to 12.2")
8+
t.Assert(Abs(-12) == 12, "-12 should equal to 12")
9+
t.Assert(Abs(-0.35) == 0.35, "-0.35 should equal to 0.35")
10+
}

math/fact.jule

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fn Fact(n: f64): f64 {
2-
if n == 0 {
3-
ret 1
4-
}
5-
ret n * Fact(n - 1)
6-
}
2+
if n == 0 {
3+
ret 1
4+
}
5+
ret n * Fact(n-1)
6+
}

math/fact_test.jule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testFact(t: &testing::T) {
7-
t.Assert(Fact(10) == 3628800, "10 fact should equal to 3628800")
8-
}
7+
t.Assert(Fact(10) == 3628800, "10 fact should equal to 3628800")
8+
}

math/fib.jule

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// O(2^n)
22
fn Fib(i: int): int {
3-
if i == 0 || i == 1 {
4-
ret i
5-
}
6-
ret Fib(i - 1) + Fib(i - 2)
3+
if i == 0 || i == 1 {
4+
ret i
5+
}
6+
ret Fib(i-1) + Fib(i-2)
77
}
88

99
// O(n * 2^n)
1010
fn FibSeq(mut n: int): []int {
11-
let mut s: []int
12-
let mut i = n
13-
for i > 0 {
14-
s = append(s, Fib(n - i + 1))
15-
i--
16-
}
17-
ret s
18-
}
11+
let mut s: []int
12+
let mut i = n
13+
for i > 0 {
14+
s = append(s, Fib(n-i+1))
15+
i--
16+
}
17+
ret s
18+
}

math/fib_test.jule

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#build test
22

3-
use testing for std::testing
4-
use slices for std::slices
3+
use "std/slices"
4+
use "std/testing"
55

66
#test
77
fn testFib(t: &testing::T) {
8-
t.Assert(Fib(6) == 8, "index 6 of fib. should be 8")
9-
t.Assert(slices::Equal(FibSeq(6), [1, 1, 2, 3, 5, 8]), "a fib. sequence up to index 6 should be 1, 1, 2, 3, 5, 8")
8+
t.Assert(Fib(6) == 8, "index 6 of fib. should be 8")
9+
t.Assert(slices::Equal(FibSeq(6), [1, 1, 2, 3, 5, 8]), "a fib. sequence up to index 6 should be 1, 1, 2, 3, 5, 8")
1010
}

math/max.jule

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fn Max(values: ...int): int {
2-
if len(values) == 0 {
3-
ret 0
4-
}
5-
let mut max = values[0]
6-
for _, x in values[1:] {
7-
if max < x {
8-
max = x
9-
}
10-
}
11-
ret max
12-
}
2+
if len(values) == 0 {
3+
ret 0
4+
}
5+
let mut max = values[0]
6+
for _, x in values[1:] {
7+
if max < x {
8+
max = x
9+
}
10+
}
11+
ret max
12+
}

math/max_test.jule

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testMax(t: &testing::T) {
7-
t.Assert(Max(0, -9024, 1, 894, -34) == 894, "max value should be 894")
7+
t.Assert(Max(0, -9024, 1, 894, -34) == 894, "max value should be 894")
88
}

math/median.jule

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use sort
1+
use "sort"
22

33
fn Median(mut slice: []int): f64 {
4-
slice = sort::QuickSort(slice)
5-
let l = len(slice)
6-
match {
7-
| l == 0:
8-
ret 0
9-
| l%2 == 0:
10-
ret f64(slice[l/2-1] + slice[l/2]) / 2
11-
|:
12-
ret f64(slice[l/2])
13-
}
4+
slice = sort::QuickSort(slice)
5+
let l = len(slice)
6+
match {
7+
| l == 0:
8+
ret 0
9+
| l%2 == 0:
10+
ret f64(slice[l/2-1]+slice[l/2]) / 2
11+
|:
12+
ret f64(slice[l/2])
13+
}
1414
}

math/median_test.jule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testMedian(t: &testing::T) {
7-
t.Assert(Median([2, 5, 2, 6, -4, -15, 1, -3]) == 1.5, "median should be 1.5")
8-
}
7+
t.Assert(Median([2, 5, 2, 6, -4, -15, 1, -3]) == 1.5, "median should be 1.5")
8+
}

math/min.jule

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
fn Min(values: ...int): int {
2-
if len(values) == 0 {
3-
ret 0
4-
}
5-
let mut min = values[0]
6-
for _, x in values[1:] {
7-
if min > x {
8-
min = x
9-
}
10-
}
11-
ret min
12-
}
2+
if len(values) == 0 {
3+
ret 0
4+
}
5+
let mut min = values[0]
6+
for _, x in values[1:] {
7+
if min > x {
8+
min = x
9+
}
10+
}
11+
ret min
12+
}

math/min_test.jule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testMin(t: &testing::T) {
7-
t.Assert(Min(0, -9024, 1, 894, -34) == -9024, "min value should be -9024")
8-
}
7+
t.Assert(Min(0, -9024, 1, 894, -34) == -9024, "min value should be -9024")
8+
}

math/q_rsqrt.jule

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
use math for std::math
1+
use "std/math"
22

33
// Fast inverse square root.
44
// See: https://en.wikipedia.org/wiki/Fast_inverse_square_root
55
fn QRsqrt(mut f: f64): f64 {
6-
const ThreeHalfs = 1.5
7-
const Magic = 0x5FE6EB50C7B537A9
6+
const ThreeHalfs = 1.5
7+
const Magic = 0x5FE6EB50C7B537A9
88

9-
let n2 = f * 0.5
10-
let b = Magic - (math::F64Bits(f) >> 1)
11-
f = math::F64FromBits(b)
12-
f *= ThreeHalfs - (n2 * f * f)
13-
ret f
14-
}
9+
let n2 = f * 0.5
10+
let b = Magic - (math::F64Bits(f) >> 1)
11+
f = math::F64FromBits(b)
12+
f *= ThreeHalfs - (n2 * f * f)
13+
ret f
14+
}

math/q_rsqrt_test.jule

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
static casesQRsqrt: [][]f64 = [
6-
[90, 0.10530667845276515],
7-
[987743, 0.001004453602645671],
8-
[2, 0.706929650795464],
9-
[224, 0.06680356325907384],
6+
[90, 0.10530667845276515],
7+
[987743, 0.001004453602645671],
8+
[2, 0.706929650795464],
9+
[224, 0.06680356325907384],
1010
]
1111

1212
#test
1313
fn testQRsqrt(t: &testing::T) {
14-
for _, c in casesQRsqrt {
15-
if QRsqrt(c[0]) != c[1] {
16-
t.Errorf("q_rsqrt({}) should be {}", c[0], c[1])
17-
}
18-
}
19-
}
14+
for _, c in casesQRsqrt {
15+
if QRsqrt(c[0]) != c[1] {
16+
t.Errorf("q_rsqrt({}) should be {}", c[0], c[1])
17+
}
18+
}
19+
}

math/sum.jule

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn Sum(slice: []int): int {
2-
let mut total: int = 0
3-
for _, i in slice {
4-
total += i
5-
}
6-
ret total
2+
let mut total: int = 0
3+
for _, i in slice {
4+
total += i
5+
}
6+
ret total
77
}

math/sum_test.jule

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testSum(t: &testing::T) {
7-
t.Assert(Sum([-9, 0, 1, 99, 54, 12]) == 157, "sum should return 157")
8-
}
7+
t.Assert(Sum([-9, 0, 1, 99, 54, 12]) == 157, "sum should return 157")
8+
}

search/binary_search.jule

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
fn BinarySearch(s: []int, i: int): (pos: int) {
2-
let mut b = 0
3-
let mut e = len(s) - 1
4-
for b <= e {
5-
let mid = int(b + (e-b)/2)
6-
match {
7-
| s[mid] > i:
8-
e = mid - 1
9-
10-
| s[mid] < i:
11-
b = mid + 1
12-
13-
|:
14-
ret mid
15-
}
16-
}
17-
ret -1
18-
}
2+
let mut b = 0
3+
let mut e = len(s) - 1
4+
for b <= e {
5+
let mid = int(b + (e-b)/2)
6+
match {
7+
| s[mid] > i:
8+
e = mid - 1
9+
| s[mid] < i:
10+
b = mid + 1
11+
|:
12+
ret mid
13+
}
14+
}
15+
ret -1
16+
}

search/binary_search_test.jule

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testBinarySearch(t: &testing::T) {
7-
let s = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]
7+
let s = [-9835, -85, -0, 0, 9, 35, 64, 89, 98, 8935]
88

9-
t.Assert(BinarySearch(s, 90) == -1, "90 should return -1")
10-
t.Assert(BinarySearch(s, -85) == 1, "85 should return 1")
11-
t.Assert(BinarySearch(s, 89) == 7, "89 should return 7")
12-
}
9+
t.Assert(BinarySearch(s, 90) == -1, "90 should return -1")
10+
t.Assert(BinarySearch(s, -85) == 1, "85 should return 1")
11+
t.Assert(BinarySearch(s, 89) == 7, "89 should return 7")
12+
}

search/linear_search.jule

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
fn LinearSearch(s: []int, i: int): (pos: int) {
2-
for j, x in s {
3-
if x == i {
4-
ret j
5-
}
6-
}
7-
ret -1
2+
for j, x in s {
3+
if x == i {
4+
ret j
5+
}
6+
}
7+
ret -1
88
}

search/linear_search_test.jule

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#build test
22

3-
use testing for std::testing
3+
use "std/testing"
44

55
#test
66
fn testLinearSearch(t: &testing::T) {
7-
let s = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89]
7+
let s = [9, 35, -0, 0, 98, 8935, -85, -9835, 64, 89]
88

9-
t.Assert(LinearSearch(s, 90) == -1, "90 should return -1")
10-
t.Assert(LinearSearch(s, -85) == 6, "-85 should return 6")
11-
}
9+
t.Assert(LinearSearch(s, 90) == -1, "90 should return -1")
10+
t.Assert(LinearSearch(s, -85) == 6, "-85 should return 6")
11+
}

0 commit comments

Comments
 (0)