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
8
4
using DataFrames
9
5
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"
12
9
10
+ @testset " ReadDBC Module Tests" begin
13
11
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
24
19
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
40
26
end
41
- end
42
27
43
- end # module readdbc
28
+ end
0 commit comments