Skip to content

Commit

Permalink
Update test framework (#19)
Browse files Browse the repository at this point in the history
* Split tests into separate files

* Add tests for AV plots

* Add tests for CG plots

* Update tests

* Bump minor version
  • Loading branch information
vnegi10 authored Jul 30, 2022
1 parent 09b958f commit e5b0ccb
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CryptoDashApp"
uuid = "8f55a569-a1ee-45d2-b761-b2b316ddd8e9"
authors = ["Vikas Negi <vikas.negi10@gmail.com>"]
version = "0.2.2"
version = "0.3.0"

[deps]
AlphaVantage = "6348297c-a006-11e8-3a05-9bbf8830fd7b"
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
140 changes: 33 additions & 107 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Test, AlphaVantage, Dates, DataFrames, CryptoDashApp, HTTP, JSON, Query
using Test, AlphaVantage, Dates, DataFrames, CryptoDashApp,
HTTP, JSON, Query, PlotlyJS

AlphaVantage.global_key!("AKTJ25ALEBBLH1QJ")

Expand All @@ -10,127 +11,52 @@ else
@info "New data folder has been created"
end

# Perform cleanup
# Perform cleanup of old data
CryptoDashApp.remove_old_files()

################# Test cases for accessing market data #################

@testset "Check if AV market data are accessible" begin

for currency in ["ETH", "LTC", "LINK"]

df_out_price, df_out_candle, df_out_vol =
CryptoDashApp.get_price_data_single(currency)

@test ~isempty(df_out_price)
@test ~isempty(df_out_candle)
@test ~isempty(df_out_vol)

end

end

@testset "Check for exception handling while accessing AV market data" begin

currency = "dummy"

@test_logs (:info, "Could not fetch data, try again later!") match_mode = :any CryptoDashApp.get_price_data_single(
currency,
)

end

################# Test cases for moving averages #################

@testset "Check if MA, MACD + signal, σ (for Bollinger bands) are calculated" begin

for currency in ["BTC", "DOT"]

df_out_price, _, _ = CryptoDashApp.get_price_data_single(currency)

duration = 90
window = 30

price_SMA, price_WMA, price_EMA =
CryptoDashApp.moving_averages(df_out_price, duration, window)

@test ~isempty(price_SMA)
@test ~isempty(price_WMA)
@test ~isempty(price_WMA)

df_out_price = df_out_price[end-duration+1-26-9+1:end, :]
df_ema_all = CryptoDashApp.calculate_macd(df_out_price)
@test ~isempty(df_ema_all)

Price_σ = CryptoDashApp.moving_std(df_out_price, duration, window)
@test ~isempty(Price_σ)

end
errors = false
all_tests = false

# Run all tests when no arguments or "all" is specified
if isempty(ARGS) || "all" in ARGS
all_tests = true
end

################# Test cases for CoinGecko API #################

@testset "Check if CG developer and community data are accessible" begin

for currency in ["btc", "eth", "ltc"]

df_dev, df_comm = CryptoDashApp.get_dev_comm_data(currency)

@test ~isempty(df_dev)
@test ~isempty(df_comm)
# Execute test in a try-catch block for each file
function execute_test(file::String, ARGS; all_tests::Bool, errors::Bool)

if all_tests || file in ARGS
try
include(file)
println("\t\033[1m\033[32mPASSED\033[0m: $(file)")
catch e
println("\t\033[1m\033[31mFAILED\033[0m: $(file)")
errors = true
showerror(stdout, e, backtrace())
println()
end
end

end

@testset "Check for exception handling while determining coin id" begin

currency = "dummy"

@test_logs (:info, "Could not find an id for the given currency") match_mode = :any CryptoDashApp.get_coin_id(
currency,
)

end

@testset "Check if CG exchange volume data per currency are accessible" begin

for currency in ["btc", "eth", "ltc"]

num_exchanges = 10

df_ex_vol = CryptoDashApp.get_exchange_vol_data(currency, num_exchanges)

@test size(df_ex_vol)[1] == num_exchanges

if errors
@warn "Some tests have failed! Check the results summary above."
end

end

@testset "Check if CG overall exchange volume data are accessible" begin

num_exchanges = 10
################# All test groups #################

for duration in [5, 10, 50, 75]
df_ex_vol = CryptoDashApp.get_overall_vol_data(duration, num_exchanges)
test_files = ["test_API_CG.jl",
"test_marketdata_AV.jl",
"test_movingaverages.jl",
"test_plots_AV.jl",
"test_plots_CG.jl"]

# Check for rows
@test size(df_ex_vol)[1] == duration
###################################################

# Check for columns, total is num_exchanges + 1 due to "Time" column
@test size(df_ex_vol)[2] == num_exchanges + 1
end
################# Execute tests ###################

@time for file in test_files
execute_test(file, ARGS, all_tests = all_tests, errors = errors)
end

#=@testset "Check if ratings data is accessible" begin
utility_score, fcas_score, dev_score, mark_score, fcas_rating = CryptoDashApp.get_ratings_data("ETH")
@test ~isempty(utility_score)
@test ~isempty(fcas_score)
@test ~isempty(dev_score)
@test ~isempty(mark_score)
@test ~isempty(fcas_rating)
end=#
###################################################
65 changes: 65 additions & 0 deletions test/test_API_CG.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
################# Test cases for CoinGecko API #################

@testset "Check if CG developer and community data are accessible" begin

for currency in ["btc", "eth", "ltc"]

df_dev, df_comm = CryptoDashApp.get_dev_comm_data(currency)

@test ~isempty(df_dev)
@test ~isempty(df_comm)

end

end

@testset "Check for exception handling while determining coin id" begin

currency = "dummy"

@test_logs (:info, "Could not find an id for the given currency") match_mode = :any CryptoDashApp.get_coin_id(
currency,
)

end

@testset "Check if CG exchange volume data per currency are accessible" begin

for currency in ["btc", "eth", "ltc"]

num_exchanges = 10

df_ex_vol = CryptoDashApp.get_exchange_vol_data(currency, num_exchanges)

@test size(df_ex_vol)[1] == num_exchanges

end

end

@testset "Check if CG overall exchange volume data are accessible" begin

num_exchanges = 10

for duration in [5, 10, 50, 75]
df_ex_vol = CryptoDashApp.get_overall_vol_data(duration, num_exchanges)

# Check for rows
@test size(df_ex_vol)[1] == duration

# Check for columns, total is num_exchanges + 1 due to "Time" column
@test size(df_ex_vol)[2] == num_exchanges + 1
end

end

#=@testset "Check if ratings data is accessible" begin
utility_score, fcas_score, dev_score, mark_score, fcas_rating = CryptoDashApp.get_ratings_data("ETH")
@test ~isempty(utility_score)
@test ~isempty(fcas_score)
@test ~isempty(dev_score)
@test ~isempty(mark_score)
@test ~isempty(fcas_rating)
end=#
26 changes: 26 additions & 0 deletions test/test_marketdata_AV.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
################# Test cases for accessing market data #################

@testset "Check if AV market data are accessible" begin

for currency in ["ETH", "LTC", "LINK"]

df_out_price, df_out_candle, df_out_vol =
CryptoDashApp.get_price_data_single(currency)

@test ~isempty(df_out_price)
@test ~isempty(df_out_candle)
@test ~isempty(df_out_vol)

end

end

@testset "Check for exception handling while accessing AV market data" begin

currency = "dummy"

@test_logs (:info, "Could not fetch data, try again later!") match_mode = :any CryptoDashApp.get_price_data_single(
currency,
)

end
28 changes: 28 additions & 0 deletions test/test_movingaverages.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
################# Test cases for moving averages #################

@testset "Check if MA, MACD + signal, σ (for Bollinger bands) are calculated" begin

for currency in ["BTC", "DOT"]

df_out_price, _, _ = CryptoDashApp.get_price_data_single(currency)

duration = 90
window = 30

price_SMA, price_WMA, price_EMA =
CryptoDashApp.moving_averages(df_out_price, duration, window)

@test ~isempty(price_SMA)
@test ~isempty(price_WMA)
@test ~isempty(price_WMA)

df_out_price = df_out_price[end-duration+1-26-9+1:end, :]
df_ema_all = CryptoDashApp.calculate_macd(df_out_price)
@test ~isempty(df_ema_all)

Price_σ = CryptoDashApp.moving_std(df_out_price, duration, window)
@test ~isempty(Price_σ)

end

end
87 changes: 87 additions & 0 deletions test/test_plots_AV.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
################# Test cases for plots using AlphaVantage data #################

@testset "plot_price_ma_trade_data" begin

all_traces = CryptoDashApp.plot_price_ma_trade_data(7, 90, 30)
@test ~isempty(all_traces)

for trace in all_traces
@test trace.fields[:y] |> length == 90
end

end

@testset "plot_price_bollinger_bands" begin

all_traces = CryptoDashApp.plot_price_bollinger_bands(13, 180, 30)
@test ~isempty(all_traces)

for trace in all_traces
@test trace.fields[:y] |> length == 180
end

end

@testset "plot_candle_vol_data" begin

all_traces = CryptoDashApp.plot_candle_vol_data(18, 180)
@test ~isempty(all_traces)

# Check candlestick data
candle_trace = all_traces[1]

for candle in [:high, :low, :open, :close]
@test candle_trace.fields[candle] |> length == 180
end

bar_trace = all_traces[2]
@test bar_trace.fields[:y] |> length == 180

end

@testset "plot_cumul_daily_return_hist" begin

all_traces = CryptoDashApp.plot_cumul_daily_return_hist(12, 60)
@test ~isempty(all_traces)

# Cumulative return
@test all_traces[1].fields[:y] |> length == 59

# Green and red returns will change with time, hence cannot be tested here

# Daily change histogram
@test all_traces[4].fields[:y] |> length == 78

end

@testset "plot_fcas_data" begin

trace1 = CryptoDashApp.plot_fcas_data(13)[1]

# Unable to get FCAS metrics from AV, so skipping tests for now [30-07-2022]
@test_skip ~isempty(trace1)
@test_skip typeof(trace1) == PlotlyBase.GenericTrace{Dict{Symbol, Any}}

end

@testset "plot_macd_signal" begin

all_traces = CryptoDashApp.plot_macd_signal(2, 42)
@test ~isempty(all_traces)

for trace in all_traces
trace.fields[:y] |> length == 43
end

end

@testset "plot_linear_regression" begin

all_traces = CryptoDashApp.plot_linear_regression(17, 200)
@test ~isempty(all_traces)

for trace in all_traces[1:4]
@test trace.fields[:y] |> length == 200
end

end
Loading

2 comments on commit e5b0ccb

@vnegi10
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

  • New test framework
  • Consistent syntax
  • No new functionality

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/65352

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.0 -m "<description of version>" e5b0ccbfc5b8fd80ec26b1d51d076bfde944ce09
git push origin v0.3.0

Please sign in to comment.