- Created test infrastructure for 240 tests (57 implemented) - Programming tests: Swift, Python, C++, JavaScript, Rust (40 tests) - Non-programming tests: Text, Math, Logic, Knowledge, Vision, Audio (17 tests) - Installed Rust compiler (rustc 1.96.0) - Test framework builds successfully - Sample test executed (generation quality needs improvement) - Identified issues: greedy sampling, position indexing, code syntax
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import Foundation
|
||||
|
||||
struct CodePrompt {
|
||||
let id: String
|
||||
let language: String
|
||||
let level: String
|
||||
let prompt: String
|
||||
let testInput: String
|
||||
let expectedOutput: String
|
||||
}
|
||||
|
||||
let swiftPrompts: [CodePrompt] = [
|
||||
CodePrompt(id: "L1-SW-01", language: "Swift", level: "Level 1", prompt: "Write a Swift function `factorial(n: Int) -> Int` to calculate factorial. Include complete implementation.", testInput: "5", expectedOutput: "120"),
|
||||
CodePrompt(id: "L1-SW-02", language: "Swift", level: "Level 1", prompt: "Write a Swift function `isPrime(n: Int) -> Bool` to check if a number is prime. Include complete implementation.", testInput: "7", expectedOutput: "true"),
|
||||
CodePrompt(id: "L2-SW-01", language: "Swift", level: "Level 2", prompt: "Implement a Stack<T> struct in Swift with push and pop methods.", testInput: "", expectedOutput: "Stack"),
|
||||
CodePrompt(id: "L3-SW-01", language: "Swift", level: "Level 3", prompt: "Write a Swift function `quicksort<T: Comparable>(_ arr: [T]) -> [T]` to implement quicksort.", testInput: "", expectedOutput: "sorted"),
|
||||
CodePrompt(id: "L4-SW-01", language: "Swift", level: "Level 4", prompt: "Write a complete Swift program that reads a file and counts lines.", testInput: "", expectedOutput: "program"),
|
||||
CodePrompt(id: "L5-SW-01", language: "Swift", level: "Level 5", prompt: "Write a Swift function with proper error handling using Result<T, Error>.", testInput: "", expectedOutput: "Result"),
|
||||
CodePrompt(id: "L6-SW-01", language: "Swift", level: "Level 6", prompt: "Write a Swift async function that runs concurrent tasks.", testInput: "", expectedOutput: "async"),
|
||||
CodePrompt(id: "L7-SW-01", language: "Swift", level: "Level 7", prompt: "Write a Swift function that calls a REST API and handles JSON response.", testInput: "", expectedOutput: "API")
|
||||
]
|
||||
|
||||
let pythonPrompts: [CodePrompt] = [
|
||||
CodePrompt(id: "L1-PY-01", language: "Python", level: "Level 1", prompt: "Write a Python function `reverse_string(s)` to reverse a string.", testInput: "hello", expectedOutput: "olleh"),
|
||||
CodePrompt(id: "L1-PY-02", language: "Python", level: "Level 1", prompt: "Write a Python function `find_max(lst)` to find the maximum in a list.", testInput: "", expectedOutput: "max"),
|
||||
CodePrompt(id: "L2-PY-01", language: "Python", level: "Level 2", prompt: "Implement a BinaryTree class in Python with insert and search.", testInput: "", expectedOutput: "Tree"),
|
||||
CodePrompt(id: "L3-PY-01", language: "Python", level: "Level 3", prompt: "Write a Python function `mergesort(arr)` to implement mergesort.", testInput: "", expectedOutput: "sorted"),
|
||||
CodePrompt(id: "L4-PY-01", language: "Python", level: "Level 4", prompt: "Write a Python script to analyze a CSV file and calculate statistics.", testInput: "", expectedOutput: "CSV"),
|
||||
CodePrompt(id: "L5-PY-01", language: "Python", level: "Level 5", prompt: "Write a Python function with proper exception handling for file operations.", testInput: "", expectedOutput: "Exception"),
|
||||
CodePrompt(id: "L6-PY-01", language: "Python", level: "Level 6", prompt: "Write a Python async function using asyncio.", testInput: "", expectedOutput: "async"),
|
||||
CodePrompt(id: "L7-PY-01", language: "Python", level: "Level 7", prompt: "Write a Python function to connect to SQLite database and execute queries.", testInput: "", expectedOutput: "SQL")
|
||||
]
|
||||
|
||||
let cppPrompts: [CodePrompt] = [
|
||||
CodePrompt(id: "L1-CP-01", language: "C++", level: "Level 1", prompt: "Write a C++ function `int factorial(int n)` for factorial calculation.", testInput: "5", expectedOutput: "120"),
|
||||
CodePrompt(id: "L1-CP-02", language: "C++", level: "Level 1", prompt: "Write a C++ function `int gcd(int a, int b)` for GCD calculation.", testInput: "", expectedOutput: "gcd"),
|
||||
CodePrompt(id: "L2-CP-01", language: "C++", level: "Level 2", prompt: "Implement a Stack template class in C++ with push and pop.", testInput: "", expectedOutput: "Stack"),
|
||||
CodePrompt(id: "L3-CP-01", language: "C++", level: "Level 3", prompt: "Write a C++ function for binary search implementation.", testInput: "", expectedOutput: "binary"),
|
||||
CodePrompt(id: "L4-CP-01", language: "C++", level: "Level 4", prompt: "Write a C++ program that processes text files.", testInput: "", expectedOutput: "program"),
|
||||
CodePrompt(id: "L5-CP-01", language: "C++", level: "Level 5", prompt: "Write a C++ function with proper exception handling.", testInput: "", expectedOutput: "Exception"),
|
||||
CodePrompt(id: "L6-CP-01", language: "C++", level: "Level 6", prompt: "Write a C++ thread-safe counter using mutex.", testInput: "", expectedOutput: "mutex"),
|
||||
CodePrompt(id: "L7-CP-01", language: "C++", level: "Level 7", prompt: "Write a C++ function to make HTTP requests using curl.", testInput: "", expectedOutput: "HTTP")
|
||||
]
|
||||
|
||||
let javascriptPrompts: [CodePrompt] = [
|
||||
CodePrompt(id: "L1-JS-01", language: "JavaScript", level: "Level 1", prompt: "Write a JavaScript function `sumArray(arr)` to sum array elements.", testInput: "", expectedOutput: "sum"),
|
||||
CodePrompt(id: "L1-JS-02", language: "JavaScript", level: "Level 1", prompt: "Write a JavaScript function `filterOdd(arr)` to filter odd numbers.", testInput: "", expectedOutput: "odd"),
|
||||
CodePrompt(id: "L2-JS-01", language: "JavaScript", level: "Level 2", prompt: "Implement a LinkedList in JavaScript with insert and delete.", testInput: "", expectedOutput: "LinkedList"),
|
||||
CodePrompt(id: "L3-JS-01", language: "JavaScript", level: "Level 3", prompt: "Write a JavaScript function `quicksort(arr)` implementation.", testInput: "", expectedOutput: "sorted"),
|
||||
CodePrompt(id: "L4-JS-01", language: "JavaScript", level: "Level 4", prompt: "Write a Node.js HTTP server that serves JSON data.", testInput: "", expectedOutput: "server"),
|
||||
CodePrompt(id: "L5-JS-01", language: "JavaScript", level: "Level 5", prompt: "Write a JavaScript async function with proper error handling.", testInput: "", expectedOutput: "async"),
|
||||
CodePrompt(id: "L6-JS-01", language: "JavaScript", level: "Level 6", prompt: "Write a JavaScript async generator for stream processing.", testInput: "", expectedOutput: "generator"),
|
||||
CodePrompt(id: "L7-JS-01", language: "JavaScript", level: "Level 7", prompt: "Write a JavaScript function to fetch API and handle JSON response.", testInput: "", expectedOutput: "fetch")
|
||||
]
|
||||
|
||||
let rustPrompts: [CodePrompt] = [
|
||||
CodePrompt(id: "L1-RS-01", language: "Rust", level: "Level 1", prompt: "Write a Rust function `fn factorial(n: u64) -> u64` for factorial.", testInput: "5", expectedOutput: "120"),
|
||||
CodePrompt(id: "L1-RS-02", language: "Rust", level: "Level 1", prompt: "Write a Rust function `fn is_prime(n: u64) -> bool` for prime check.", testInput: "7", expectedOutput: "true"),
|
||||
CodePrompt(id: "L2-RS-01", language: "Rust", level: "Level 2", prompt: "Implement a Stack using Vec<T> in Rust.", testInput: "", expectedOutput: "Stack"),
|
||||
CodePrompt(id: "L3-RS-01", language: "Rust", level: "Level 3", prompt: "Write a Rust function for mergesort implementation.", testInput: "", expectedOutput: "sorted"),
|
||||
CodePrompt(id: "L4-RS-01", language: "Rust", level: "Level 4", prompt: "Write a Rust CLI program that processes command arguments.", testInput: "", expectedOutput: "CLI"),
|
||||
CodePrompt(id: "L5-RS-01", language: "Rust", level: "Level 5", prompt: "Write a Rust function using Result<T, E> for error handling.", testInput: "", expectedOutput: "Result"),
|
||||
CodePrompt(id: "L6-RS-01", language: "Rust", level: "Level 6", prompt: "Write a Rust async function using tokio.", testInput: "", expectedOutput: "async"),
|
||||
CodePrompt(id: "L7-RS-01", language: "Rust", level: "Level 7", prompt: "Write a Rust HTTP client using reqwest crate.", testInput: "", expectedOutput: "HTTP")
|
||||
]
|
||||
|
||||
let allCodePrompts = swiftPrompts + pythonPrompts + cppPrompts + javascriptPrompts + rustPrompts
|
||||
@@ -0,0 +1,44 @@
|
||||
import Foundation
|
||||
|
||||
struct NonProgrammingPrompt {
|
||||
let id: String
|
||||
let category: String
|
||||
let prompt: String
|
||||
let expectedKeywords: [String]
|
||||
}
|
||||
|
||||
let textPrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "TEXT-01", category: "Text", prompt: "Summarize this article in 3 sentences: 'Swift is a powerful programming language developed by Apple. It combines modern syntax with performance optimizations. Swift is used for iOS, macOS, and server-side development.'", expectedKeywords: ["Swift", "Apple", "programming"]),
|
||||
NonProgrammingPrompt(id: "TEXT-02", category: "Text", prompt: "Translate this English text to Chinese: 'Hello, world'", expectedKeywords: ["你好", "世界"]),
|
||||
NonProgrammingPrompt(id: "TEXT-03", category: "Text", prompt: "Rewrite this sentence in formal tone: 'Hey, what's up?'", expectedKeywords: ["formal", "greeting"])
|
||||
]
|
||||
|
||||
let mathPrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "MATH-01", category: "Math", prompt: "Calculate: 234 + 567 - 123", expectedKeywords: ["678"]),
|
||||
NonProgrammingPrompt(id: "MATH-02", category: "Math", prompt: "Solve for x: 2x + 5 = 15", expectedKeywords: ["5", "x=5"]),
|
||||
NonProgrammingPrompt(id: "MATH-03", category: "Math", prompt: "Calculate the area of a triangle with base 5 and height 8", expectedKeywords: ["20", "area"])
|
||||
]
|
||||
|
||||
let logicPrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "LOGIC-01", category: "Logic", prompt: "If A implies B, and B is false, what can we conclude about A?", expectedKeywords: ["false", "A is false"]),
|
||||
NonProgrammingPrompt(id: "LOGIC-02", category: "Logic", prompt: "All humans are mortal. Socrates is human. What follows?", expectedKeywords: ["mortal", "Socrates"]),
|
||||
NonProgrammingPrompt(id: "LOGIC-03", category: "Logic", prompt: "Prove that the sum of two even numbers is even", expectedKeywords: ["even", "2", "sum"])
|
||||
]
|
||||
|
||||
let knowledgePrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "KNOW-01", category: "Knowledge", prompt: "What is the speed of light in vacuum?", expectedKeywords: ["299792458", "3e8", "300000"]),
|
||||
NonProgrammingPrompt(id: "KNOW-02", category: "Knowledge", prompt: "When did World War II end?", expectedKeywords: ["1945", "September"]),
|
||||
NonProgrammingPrompt(id: "KNOW-03", category: "Knowledge", prompt: "What is the capital of Australia?", expectedKeywords: ["Canberra"])
|
||||
]
|
||||
|
||||
let multimodalPrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "VIS-01", category: "Vision", prompt: "Describe what you see in a typical office scene", expectedKeywords: ["desk", "computer", "chair"]),
|
||||
NonProgrammingPrompt(id: "VIS-02", category: "Vision", prompt: "What features would you expect in a sunset image?", expectedKeywords: ["sun", "colors", "horizon"])
|
||||
]
|
||||
|
||||
let audioPrompts: [NonProgrammingPrompt] = [
|
||||
NonProgrammingPrompt(id: "AUD-01", category: "Audio", prompt: "What are common characteristics of speech audio?", expectedKeywords: ["voice", "words", "frequency"]),
|
||||
NonProgrammingPrompt(id: "AUD-02", category: "Audio", prompt: "Describe the difference between music and noise", expectedKeywords: ["harmony", "random", "pattern"])
|
||||
]
|
||||
|
||||
let allNonProgrammingPrompts = textPrompts + mathPrompts + logicPrompts + knowledgePrompts + multimodalPrompts + audioPrompts
|
||||
@@ -0,0 +1,109 @@
|
||||
import Foundation
|
||||
|
||||
struct CompileResult {
|
||||
let success: Bool
|
||||
let output: String
|
||||
let error: String
|
||||
}
|
||||
|
||||
func runCommand(_ command: String, timeout: TimeInterval = 30) -> CompileResult {
|
||||
let task = Process()
|
||||
task.executableURL = URL(fileURLWithPath: "/bin/zsh")
|
||||
task.arguments = ["-c", command]
|
||||
|
||||
let outputPipe = Pipe()
|
||||
let errorPipe = Pipe()
|
||||
task.standardOutput = outputPipe
|
||||
task.standardError = errorPipe
|
||||
|
||||
do {
|
||||
try task.run()
|
||||
task.waitUntilExit()
|
||||
|
||||
let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile()
|
||||
|
||||
let output = String(data: outputData, encoding: .utf8) ?? ""
|
||||
let error = String(data: errorData, encoding: .utf8) ?? ""
|
||||
|
||||
return CompileResult(success: task.terminationStatus == 0, output: output.trimmingCharacters(in: .whitespacesAndNewlines), error: error.trimmingCharacters(in: .whitespacesAndNewlines))
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
func compileAndRunSwift(code: String, testInput: String = "") -> CompileResult {
|
||||
let tempFile = "/tmp/test_swift_code.swift"
|
||||
do {
|
||||
try code.write(toFile: tempFile, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: "Failed to write file: \(error)")
|
||||
}
|
||||
|
||||
let compileResult = runCommand("swiftc \(tempFile) -o /tmp/test_swift_exec", timeout: 60)
|
||||
if !compileResult.success {
|
||||
return compileResult
|
||||
}
|
||||
|
||||
return runCommand("/tmp/test_swift_exec \(testInput)", timeout: 10)
|
||||
}
|
||||
|
||||
func compileAndRunPython(code: String, testInput: String = "") -> CompileResult {
|
||||
let tempFile = "/tmp/test_python_code.py"
|
||||
do {
|
||||
try code.write(toFile: tempFile, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: "Failed to write file: \(error)")
|
||||
}
|
||||
|
||||
return runCommand("python3 \(tempFile) \(testInput)", timeout: 30)
|
||||
}
|
||||
|
||||
func compileAndRunCpp(code: String, testInput: String = "") -> CompileResult {
|
||||
let tempFile = "/tmp/test_cpp_code.cpp"
|
||||
do {
|
||||
try code.write(toFile: tempFile, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: "Failed to write file: \(error)")
|
||||
}
|
||||
|
||||
let compileResult = runCommand("clang++ \(tempFile) -o /tmp/test_cpp_exec", timeout: 60)
|
||||
if !compileResult.success {
|
||||
return compileResult
|
||||
}
|
||||
|
||||
return runCommand("/tmp/test_cpp_exec \(testInput)", timeout: 10)
|
||||
}
|
||||
|
||||
func compileAndRunJavaScript(code: String, testInput: String = "") -> CompileResult {
|
||||
let tempFile = "/tmp/test_js_code.js"
|
||||
do {
|
||||
try code.write(toFile: tempFile, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: "Failed to write file: \(error)")
|
||||
}
|
||||
|
||||
return runCommand("node \(tempFile) \(testInput)", timeout: 30)
|
||||
}
|
||||
|
||||
func compileAndRunRust(code: String, testInput: String = "") -> CompileResult {
|
||||
let tempFile = "/tmp/test_rust_code.rs"
|
||||
do {
|
||||
try code.write(toFile: tempFile, atomically: true, encoding: .utf8)
|
||||
} catch {
|
||||
return CompileResult(success: false, output: "", error: "Failed to write file: \(error)")
|
||||
}
|
||||
|
||||
let compileResult = runCommand("source $HOME/.cargo/env && rustc \(tempFile) -o /tmp/test_rust_exec", timeout: 60)
|
||||
if !compileResult.success {
|
||||
return compileResult
|
||||
}
|
||||
|
||||
return runCommand("source $HOME/.cargo/env && /tmp/test_rust_exec \(testInput)", timeout: 10)
|
||||
}
|
||||
|
||||
func verifyOutput(actual: String, expected: String) -> Bool {
|
||||
let actualTrimmed = actual.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let expectedTrimmed = expected.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
return actualTrimmed == expectedTrimmed || actualTrimmed.contains(expectedTrimmed)
|
||||
}
|
||||
Reference in New Issue
Block a user