-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up examples/. Add test/examples.jl to track breakage for exampl…
…es. Fixes #7332.
- Loading branch information
Showing
10 changed files
with
107 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
require("lru") | ||
using LRUExample | ||
|
||
const TestLRU = UnboundedLRU{ASCIIString, ASCIIString}() | ||
const TestBLRUs = BoundedLRU{ASCIIString, ASCIIString}(100) | ||
const TestBLRUm = BoundedLRU{ASCIIString, ASCIIString}(1000) | ||
const TestBLRUl = BoundedLRU{ASCIIString, ASCIIString}(10000) | ||
const TestBLRUxl = BoundedLRU{ASCIIString, ASCIIString}(100000) | ||
TestLRU = LRUExample.UnboundedLRU{ASCIIString, ASCIIString}() | ||
TestBLRU = LRUExample.BoundedLRU{ASCIIString, ASCIIString}(1000) | ||
|
||
get_str(i) = ascii(vcat(map(x->[x>>4; x&0x0F], reinterpret(Uint8, [int32(i)]))...)) | ||
|
||
isbounded{L<:LRU}(::Type{L}) = any(map(n->n==:maxsize, L.names)) | ||
isbounded{L<:LRU}(l::L) = isbounded(L) | ||
isbounded{L<:LRUExample.LRU}(::Type{L}) = any(map(n->n==:maxsize, L.names)) | ||
isbounded{L<:LRUExample.LRU}(l::L) = isbounded(L) | ||
|
||
nmax = int(logspace(2, 5, 4)) | ||
|
||
println("LRU consistency tests") | ||
for lru in ( | ||
TestLRU, | ||
TestBLRUs, | ||
TestBLRUm, | ||
TestBLRUl, | ||
TestBLRUxl, | ||
) | ||
for n in nmax | ||
empty!(lru) | ||
@printf(" %s, %d items\n", lru, n) | ||
print(" Simple eviction: ") | ||
for i in 1:n | ||
str = get_str(i) | ||
lru[str] = str | ||
@assert lru.q[1].v == str | ||
if isbounded(lru) && length(lru) >= lru.maxsize | ||
tailstr = get_str(i-lru.maxsize+1) | ||
@assert lru.q[end].v == tailstr | ||
function lrutest() | ||
#println("LRU consistency tests") | ||
for lru in (TestLRU,TestBLRU) | ||
for n in nmax | ||
empty!(lru) | ||
#@printf(" %s, %d items\n", lru, n) | ||
#print(" Simple eviction: ") | ||
for i in 1:n | ||
str = get_str(i) | ||
lru[str] = str | ||
@assert lru.q[1].v == str | ||
if isbounded(lru) && length(lru) >= lru.maxsize | ||
tailstr = get_str(i-lru.maxsize+1) | ||
@assert lru.q[end].v == tailstr | ||
end | ||
end | ||
end | ||
println("pass") | ||
#println("pass") | ||
|
||
print(" Lookup, random access: ") | ||
for i in 1:n | ||
str = get_str(rand(1:n)) | ||
if haskey(lru, str) # the bounded LRUs can have cache misses | ||
blah = lru[str] | ||
@assert lru.q[1].v == blah | ||
#print(" Lookup, random access: ") | ||
for i in 1:n | ||
str = get_str(rand(1:n)) | ||
if haskey(lru, str) # the bounded LRUs can have cache misses | ||
blah = lru[str] | ||
@assert lru.q[1].v == blah | ||
end | ||
end | ||
#println("pass") | ||
end | ||
println("pass") | ||
empty!(lru) | ||
end | ||
empty!(lru) | ||
end | ||
|
||
lrutest() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
addqueen(queens::Array{Vector{Int}}, queen::Vector{Int}) = push!(copy(queens), queen) | ||
|
||
hitsany(queen::Vector{Int}, queens::Array{Vector{Int}}) = any(map((x) -> hits(queen, x), queens)) | ||
hitsany(queen::Vector{Int}, queens::Array{Vector{Int}}) = any(map(x->hits(queen, x), queens)) | ||
hits(a::Array{Int}, b::Array{Int}) = any(a .== b) || abs(a-b)[1] == abs(a-b)[2] | ||
|
||
function solve(x::Int, y::Int, n::Int, d::Array{Vector{Int}}) | ||
function solve(x, y, n, d=Array(Vector{Int}, 0)) | ||
if n == 0 | ||
return d | ||
end | ||
for px = 1:x | ||
for py = 1:y | ||
if !hitsany([px, py], d) | ||
s = solve(x, y, n-1, addqueen(d, [px, py])) | ||
if !isequal(s, None) | ||
return s | ||
end | ||
s != nothing && return s | ||
end | ||
end | ||
end | ||
return None | ||
end | ||
|
||
solve(x, y, n) = solve(x, y, n, Array(Vector{Int}, 0)) | ||
|
||
for i = 1:8 | ||
print("Solve for $i\n") | ||
print(solve(8, 8, i)) | ||
print("\n") | ||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
include("../examples/bubblesort.jl") | ||
a = rand(1:100,100) | ||
@test issorted(sort!(a;alg=BubbleSort)) | ||
|
||
include("../examples/enum.jl") | ||
@enum TestEnum TestEnum1 TestEnum2 TestEnum3 | ||
@test [TestEnum1.n,TestEnum2.n,TestEnum3.n] == [0,1,2] | ||
|
||
include("../examples/lru.jl") | ||
include("../examples/lru_test.jl") | ||
|
||
include("../examples/modint.jl") | ||
b = ModInts.ModInt{10}(2) | ||
c = ModInts.ModInt{10}(4) | ||
@test b + c == ModInts.ModInt{10}(6) | ||
@test c - b == ModInts.ModInt{10}(2) | ||
|
||
include("../examples/ndgrid.jl") | ||
r = repmat(1:10,1,10) | ||
r1, r2 = ndgrid(1:10, 1:10) | ||
@test r1 == r | ||
@test r2 == r' | ||
r3, r4 = meshgrid(1:10,1:10) | ||
@test r3 == r' | ||
@test r4 == r | ||
|
||
include("../examples/quaternion.jl") | ||
q = Quaternions.Quaternion(1,0,0,0) | ||
x = Quaternions.Quaternion(0,1,1,1) | ||
@test q*2.0+2 == Quaternions.Quaternion(4,0,0,0) | ||
@test abs((-q+x*2)/4) == 0.9013878188659973 | ||
|
||
include("../examples/queens.jl") | ||
@test solve(8, 8, 1) == Array{Int,1}[[1,1]] | ||
@test solve(8, 8, 7) == Array{Int,1}[[1,1],[2,3],[3,5],[4,2],[5,8],[7,4],[8,7]] | ||
|
||
# At least make sure code laods | ||
include("../examples/plife.jl") | ||
|
||
include("../examples/preduce.jl") | ||
|
||
include("../examples/wordcount.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters