Skip to content

Commit 493b741

Browse files
committed
changes to src and test file and precompile
1 parent f4d7f41 commit 493b741

File tree

4 files changed

+25
-42
lines changed

4 files changed

+25
-42
lines changed

src/ABOAC1909.dbf

3.92 KB
Binary file not shown.

src/ReadDBC.jl

+21-36
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,28 @@
1-
module ReadDBC
2-
3-
# Export functions
4-
export dbcTable, dbctodbf
5-
6-
# Importing packages
7-
using DBFTables
1+
# test/test_read_dbc.jl
2+
using Test # Import the Test package to write test cases
3+
using ReadDBC # Import your module to test its functions
84
using DataFrames
95

10-
using DBCtoDBF_jll
11-
6+
# Define paths for test input and expected output
7+
input_file = "src/ABOAC1909.dbc"
8+
output_file = "src/ABOAC1909.dbf"
129

10+
@testset "ReadDBC Module Tests" begin
1311

14-
# Defining function dbctodbf
15-
function dbctodbf(input_file::String, output_file::String)
16-
# The DBCtoDBF_jll package provides the dbc2dbf executable directly
17-
exe_path = dbc2dbf() # This gives the path to the dbc2dbf executable
18-
19-
# Run the executable with the input and output file arguments
20-
run(`$exe_path $input_file $output_file`)
21-
22-
return output_file # Optionally return the output file name
23-
end
12+
# Test 1: Test dbctodbf function
13+
@testset "Test dbctodbf" begin
14+
@test isfile(input_file) # Check if the input file exists
15+
result = dbctodbf(input_file, output_file) # Call the function
16+
@test result == output_file # Ensure the output file path is returned
17+
@test isfile(output_file) # Check if the output file was created
18+
end
2419

25-
# Defining function readdbc
26-
function dbcTable(input_file::String)
27-
output_file = replace(input_file, ".dbc" => ".dbf")
28-
try
29-
# Convert the DBC file to a DBF file
30-
dbctodbf(input_file, output_file)
31-
32-
# Read the DBF file into a DataFrame
33-
df = DBFTables.Table(output_file)
34-
return DataFrame(df)
35-
36-
catch e
37-
@error "Failed to convert or read DBC file: $input_file"
38-
@error "$e"
39-
return nothing
20+
# Test 2: Test dbcTable function
21+
@testset "Test dbcTable" begin
22+
df = dbcTable(input_file) # Call the function to convert and read
23+
@test df !== nothing # Ensure the DataFrame is not empty
24+
@test isa(df, DataFrame) # Ensure the result is a DataFrame
25+
@test nrow(df) > 0 # Ensure the DataFrame has rows
4026
end
41-
end
4227

43-
end # module readdbc
28+
end

src/how_to_use.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
using .ReadDBC
1+
using ReadDBC
22

33
df = dbcTable("src/ABOAC1909.dbc")

test/runtests.jl

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
using Test
2-
using .ReadDBC
2+
using ReadDBC
33
using DataFrames
44

55

66
# Test the dbctodbf function
77
@testset "ReadDBC Tests" begin
88
# Set up file paths
99
input_file = "src/ABOAC1909.dbc"
10-
output_file = "src/ABOAC1909.dbf"
11-
12-
# Call the dbctodbf function
13-
result = dbctodbf(input_file, output_file)
10+
output_file = "src/ABOAC1909.dbf"
11+
dbctodbf(input_file, output_file)
1412

1513
# Check if the output file is created (basic test)
1614
@test isfile(output_file)

0 commit comments

Comments
 (0)