runner.jl (1406B)
1 #!/usr/bin/env julia 2 # 3 # @license Apache-2.0 4 # 5 # Copyright (c) 2018 The Stdlib Authors. 6 # 7 # Licensed under the Apache License, Version 2.0 (the "License"); 8 # you may not use this file except in compliance with the License. 9 # You may obtain a copy of the License at 10 # 11 # http://www.apache.org/licenses/LICENSE-2.0 12 # 13 # Unless required by applicable law or agreed to in writing, software 14 # distributed under the License is distributed on an "AS IS" BASIS, 15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 # See the License for the specific language governing permissions and 17 # limitations under the License. 18 19 import JSON 20 21 """ 22 gen( domain, filepath ) 23 24 Generate fixture data and write to file. 25 26 # Arguments 27 28 * `domain`: domain 29 * `filepath::AbstractString`: filepath of the output file 30 31 # Examples 32 33 ``` julia 34 julia> x = range( -1000, stop = 1000, length = 2001 ); 35 julia> gen( x, \"./data.json\" ); 36 ``` 37 """ 38 function gen( domain, filepath ) 39 x = collect( domain ); 40 y = log.( x ); 41 data = Dict([ 42 ("x", x), 43 ("expected", y) 44 ]); 45 outfile = open( filepath, "w" ); 46 write( outfile, JSON.json(data) ); 47 close( outfile ); 48 end 49 50 # Get the filename: 51 file = @__FILE__; 52 53 # Extract the directory in which this file resides: 54 dir = dirname( file ); 55 56 # Generate fixture data for decimal values: 57 x = range( 0.1, stop = 1000.0, length = 2003 ) 58 out = joinpath( dir, "data.json" ); 59 gen( x, out );