-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add command to generate skeleton for Barq strategy #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we should also include some usage instructions, at least mentioning it in the README. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This script doesn't add the strategy to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#!/bin/bash | ||
|
||
capitalize() { | ||
echo "$1" | awk '{print toupper(substr($0,1,1)) tolower(substr($0,2))}' | ||
} | ||
|
||
script_dir=$(dirname "$(realpath "$0")") | ||
|
||
mkdir -p "$script_dir/src/algorithms" | ||
|
||
read -p "Enter the name of your strategy: " script_name | ||
|
||
capitalized_script_name=$(capitalize "$script_name") | ||
|
||
if [ -f "$script_dir/src/algorithms/${script_name}.rs" ]; then | ||
echo "Error: $script_dir/src/algorithms/${script_name}.rs already exists." | ||
exit 1 | ||
fi | ||
|
||
cat <<EOL > "$script_dir/src/algorithms/${script_name}.rs" | ||
use anyhow::Result; | ||
|
||
use crate::strategy::{RouteHop, RouteInput, RouteOutput, Strategy}; | ||
|
||
const DEFAULT_DELAY: u64 = 9; | ||
|
||
pub struct $capitalized_script_name; | ||
|
||
impl $capitalized_script_name { | ||
pub fn new() -> Self { | ||
$capitalized_script_name | ||
} | ||
} | ||
|
||
impl Default for $capitalized_script_name { | ||
fn default() -> Self { | ||
$capitalized_script_name::new() | ||
} | ||
} | ||
|
||
impl Strategy for $capitalized_script_name { | ||
fn can_apply(&self, input: &RouteInput) -> Result<bool> { | ||
// TODO: implement logic which checks if this strategy can be applied to given network graph | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These will cause compilation errors. The function returns |
||
} | ||
|
||
fn route(&self, input: &RouteInput) -> Result<RouteOutput> { | ||
// TODO: implement routing algorithm | ||
} | ||
Comment on lines
+46
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::{ | ||
graph::{Edge, NetworkGraph, Node}, | ||
strategy::Router, | ||
}; | ||
|
||
#[test] | ||
fn test_direct_routing() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should modify this too? |
||
// TODO: write tests for $capitalized_script_name strategy | ||
} | ||
} | ||
EOL | ||
|
||
echo "Strategy ${script_name} created in $script_dir/src/algorithms/${script_name}.rs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is missing an inclusion line in
lib.rs
, causing it to fail to compile.