mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vlib: update and cleanup tests + fix PR template
This commit is contained in:
parent
2dccdd347f
commit
f4f1622528
4
.github/PULL_REQUEST_TEMPLATE
vendored
4
.github/PULL_REQUEST_TEMPLATE
vendored
@ -18,8 +18,8 @@ fn test_foo() {
|
||||
|
||||
Before submitting a PR, please run the tests with `make test`, and make sure V can still compile itself. Run this twice:
|
||||
|
||||
./v -o v
|
||||
./v -o v
|
||||
./v -o v compiler
|
||||
./v -o v compiler
|
||||
|
||||
I try to process PRs as soon as possible. They should be handled within 24 hours.
|
||||
|
||||
|
@ -11,31 +11,29 @@ fn test_ints() {
|
||||
assert a[0] == 1
|
||||
assert a[2] == 2
|
||||
assert a.last() == 3
|
||||
println(a)
|
||||
a << 4
|
||||
println(a)
|
||||
assert a.len == 5
|
||||
assert a[4] == 4
|
||||
assert a.last() == 4
|
||||
// assert a.contains(4) == true
|
||||
// assert a.contains(777) == false
|
||||
// assert a.str() == '51234'
|
||||
|
||||
mut s := a.str()
|
||||
assert s == '[1, 5, 2, 3, 4]'
|
||||
// Insert
|
||||
// val := 5
|
||||
// a.insert(1, val)// 1 5 2 3 4
|
||||
s = a.str()
|
||||
assert a[1] == 5
|
||||
assert a.last() == 4
|
||||
// a.sort()
|
||||
s = a.str()
|
||||
assert s == '[1, 5, 2, 3, 4]'
|
||||
// Delete
|
||||
}
|
||||
|
||||
fn test_deleting() {
|
||||
mut a := [1, 5, 2, 3, 4]
|
||||
assert a.len == 5
|
||||
assert a.str() == '[1, 5, 2, 3, 4]'
|
||||
|
||||
a.delete(0)
|
||||
assert a.str() == '[5, 2, 3, 4]'
|
||||
assert a.len == 4
|
||||
|
||||
a.delete(1)
|
||||
assert a.str() == '[5, 3, 4]'
|
||||
assert a.len == 3
|
||||
}
|
||||
|
||||
fn test_short() {
|
||||
@ -75,6 +73,7 @@ fn test_empty() {
|
||||
chunks << a
|
||||
assert chunks.len == 1
|
||||
}
|
||||
|
||||
fn test_push() {
|
||||
mut a := []int
|
||||
a << 1
|
||||
@ -84,20 +83,18 @@ fn test_push() {
|
||||
}
|
||||
|
||||
fn test_strings() {
|
||||
s := 'hi'
|
||||
if s.contains('i') {
|
||||
// println('$s')
|
||||
}
|
||||
a := ['a', 'b', 'c']
|
||||
assert a.str() == '["a", "b", "c"]'
|
||||
// println(a)
|
||||
}
|
||||
|
||||
fn test_repeat() {
|
||||
a := [0; 5]
|
||||
// a := [0 x 5]
|
||||
assert a.len == 5
|
||||
assert a[0] == 0 && a[1] == 0 && a[2] == 0 && a[3] == 0 && a[4] == 0
|
||||
|
||||
b := [7; 3]
|
||||
assert b.len == 3
|
||||
assert b[0] == 7 && b[1] == 7 && b[2] == 7
|
||||
}
|
||||
|
||||
fn test_right() {
|
||||
@ -117,11 +114,9 @@ fn test_left() {
|
||||
fn test_slice() {
|
||||
a := [1, 2, 3, 4]
|
||||
b := a.slice(2, 4)
|
||||
for val in b {
|
||||
println(val)
|
||||
}
|
||||
assert b.len == 2
|
||||
assert a.slice(1, 2).len == 1
|
||||
println(a.slice(2, 4))
|
||||
assert a.len == 4
|
||||
}
|
||||
|
||||
fn test_push_many() {
|
||||
@ -132,7 +127,6 @@ fn test_push_many() {
|
||||
assert a[0] == 1
|
||||
assert a[3] == 4
|
||||
assert a[5] == 6
|
||||
println(a)
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,9 +1,15 @@
|
||||
import math
|
||||
|
||||
fn test_gcd_and_lcm() {
|
||||
fn test_gcd() {
|
||||
assert math.gcd(6, 9) == 3
|
||||
assert math.gcd(6, -9) == 3
|
||||
assert math.gcd(-6, -9) == 3
|
||||
assert math.gcd(0, 0) == 0
|
||||
}
|
||||
|
||||
fn test_lcm() {
|
||||
assert math.lcm(2, 3) == 6
|
||||
assert math.lcm(-2, 3) == 6
|
||||
assert math.lcm(-2, -3) == 6
|
||||
assert math.lcm(0, 0) == 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user