#[tokio::test]
async fn test_analyze_file_complexity_heuristic() {
let analyzer = SimpleDeepContext;
let temp_dir = TempDir::new().unwrap();
let py_file = temp_dir.path().join("test.py");
fs::write(
&py_file,
r#"
def simple_function():
return 42
def complex_function(x):
if x > 0:
for i in range(x):
if i % 2 == 0:
print(i)
else:
continue
elif x < 0:
while x < 0:
x += 1
else:
try:
return 1 / x
except:
return 0
"#,
)
.unwrap();
let (count, high, avg) = analyzer
.analyze_file_complexity_heuristic(&py_file, "py")
.await
.unwrap();
assert_eq!(count, 2);
assert!(high <= 1); assert!(avg >= 1.0);
let js_file = temp_dir.path().join("test.js");
fs::write(
&js_file,
r#"
function simpleFunc() {
return 42;
}
const complexFunc = (x) => {
if (x > 0) {
for (let i = 0; i < x; i++) {
if (i % 2 === 0) {
console.log(i);
}
}
}
return x;
};
"#,
)
.unwrap();
let (count, high, avg) = analyzer
.analyze_file_complexity_heuristic(&js_file, "js")
.await
.unwrap();
assert!(count >= 2); assert!(high <= count); assert!(avg >= 1.0); }
#[tokio::test]
async fn test_analyze_file_complexity_heuristic_c() {
let analyzer = SimpleDeepContext;
let temp_dir = TempDir::new().unwrap();
let c_file = temp_dir.path().join("test.c");
fs::write(
&c_file,
r#"
int main() {
if (x > 0) {
for (int i = 0; i < 10; i++) {
printf("%d\n", i);
}
}
return 0;
}
void helper() {
while (running) {
process();
}
}
"#,
)
.unwrap();
let (count, _high, avg) = analyzer
.analyze_file_complexity_heuristic(&c_file, "c")
.await
.unwrap();
assert!(count >= 2);
assert!(avg >= 1.0);
}
#[tokio::test]
async fn test_analyze_file_complexity_heuristic_go() {
let analyzer = SimpleDeepContext;
let temp_dir = TempDir::new().unwrap();
let go_file = temp_dir.path().join("test.go");
fs::write(
&go_file,
r#"
func main() {
fmt.Println("hello")
}
func helper(x int) int {
if x > 0 {
return x * 2
}
return 0
}
"#,
)
.unwrap();
let (count, _high, avg) = analyzer
.analyze_file_complexity_heuristic(&go_file, "go")
.await
.unwrap();
assert!(count >= 2);
assert!(avg >= 1.0);
}