Skip to content

Commit 8685bbc

Browse files
author
Gonzalo Diaz
committed
Introducing logging
1 parent 7d5d73f commit 8685bbc

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ crate-type = ["rlib", "cdylib"]
1111
serde_json = "1.0"
1212
serde = { version = "1.0", features = ["derive"] }
1313
once_cell = "1.21.3"
14+
log = "0.4.28"

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
## (1) ## Allowed values: info | warn | error | debug
1313
LOG_LEVEL ?= info
1414
## (3) (4)
15-
LOG_LEVEL :=$(shell echo '${LOG_LEVEL}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')
15+
LOG_LEVEL :=$(shell echo '${LOG_LEVEL}'| tr '[:upper:]' '[:lower:]'| tr -d '[:blank:]')
1616

1717
## (1) ## Allowed values: true | false
1818
BRUTEFORCE ?= false
1919
## (3) (4)
20-
BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:lower:]' '[:upper:]'| tr -d '[:blank:]')
20+
BRUTEFORCE :=$(shell echo '${BRUTEFORCE}'| tr '[:upper:]' '[:lower:]'| tr -d '[:blank:]')
2121

2222
# DOCKER
2323
DOCKER_COMPOSE=docker compose
@@ -83,7 +83,7 @@ format:
8383
$(PACKAGE_MANAGER) fix --allow-dirty --allow-staged --all-features
8484

8585
test: env dependencies
86-
$(PACKAGE_MANAGER) test
86+
RUST_LOG=${LOG_LEVEL} $(PACKAGE_MANAGER) test -- --nocapture
8787

8888
coverage: test
8989
$(PACKAGE_MANAGER) llvm-cov --all-features --workspace --lcov --output-path lcov.info

src/hackerrank/warmup/mini_max_sum.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// @link Problem definition [[docs/hackerrank/warmup/mini_max_sum.md]]
22

3+
#[cfg(not(test))]
4+
use log::{info}; // Use log crate when building application
5+
6+
#[cfg(test)]
7+
use std::{println as info}; // Workaround to use prinltn! for logs.
8+
39
pub fn mini_max_sum(arr: &[i32]) -> String {
410
if arr.is_empty() {
511
panic!("Empty input");
@@ -28,7 +34,10 @@ pub fn mini_max_sum(arr: &[i32]) -> String {
2834
result
2935
}
3036

31-
#[allow(non_snake_case)]
37+
#[allow(non_snake_case, reason = "Keeping original interface from HackerRank")]
3238
pub fn miniMaxSum(arr: &[i32]) {
33-
print!("{}", mini_max_sum(arr))
39+
let result = mini_max_sum(arr);
40+
41+
info!("miniMaxSum result => {}" , result);
42+
println!("{}", mini_max_sum(arr))
3443
}

tests/hackerrank/warmup/mini_max_sum.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use serde::Deserialize;
44

55
use crate::common;
66
use common::utils::load_json;
7+
use log::{warn};
78

89
#[cfg(test)]
910
mod tests {
@@ -26,7 +27,9 @@ mod tests {
2627
for test_case in TEST_DATA.iter() {
2728
let slice: &[i32] = &test_case.input;
2829
let result = mini_max_sum(slice);
29-
miniMaxSum(slice);
30+
// miniMaxSum(slice);
31+
32+
warn!("miniMaxSum ({}) result => {}" , test_case.title, result);
3033

3134
assert_eq!(result, test_case.expected);
3235
}

0 commit comments

Comments
 (0)