add adder project (testing examples)

This commit is contained in:
Timothy Warren 2019-01-31 15:09:52 -05:00
parent 65f88596cb
commit 9fec8ed7f9
7 changed files with 278 additions and 52 deletions

1
.idea/misc.xml generated
View File

@ -19,6 +19,7 @@
<cargoProject FILE="$PROJECT_DIR$/largest_number/src/main.rs" />
<cargoProject FILE="$PROJECT_DIR$/generics/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/lifetimes/Cargo.toml" />
<cargoProject FILE="$PROJECT_DIR$/adder/Cargo.toml" />
</component>
<component name="ComposerJsonPluginSettings">
<unboundedVersionInspectionSettings>

5
.idea/rust.iml generated
View File

@ -74,6 +74,11 @@
<sourceFolder url="file://$MODULE_DIR$/lifetimes/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/lifetimes/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/lifetimes/benches" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/adder/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/adder/examples" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/adder/tests" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/adder/benches" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/adder/target" />
<excludeFolder url="file://$MODULE_DIR$/branches/target" />
<excludeFolder url="file://$MODULE_DIR$/ctof/target" />
<excludeFolder url="file://$MODULE_DIR$/enums/target" />

201
.idea/workspace.xml generated
View File

@ -14,19 +14,49 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lifetimes/src/main.rs">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/adder/src/lib.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="912">
<caret line="57" lean-forward="true" selection-start-line="57" selection-end-line="57" />
<state relative-caret-position="1025">
<caret line="66" column="5" selection-start-line="66" selection-start-column="5" selection-end-line="66" selection-end-column="5" />
<folding>
<element signature="e#111#112#0" expanded="true" />
<element signature="e#127#128#0" expanded="true" />
<element signature="e#251#252#0" expanded="true" />
<element signature="e#263#264#0" expanded="true" />
<element signature="e#304#305#0" expanded="true" />
<element signature="e#338#339#0" expanded="true" />
<element signature="e#1036#1037#0" expanded="true" />
<element signature="e#1077#1078#0" expanded="true" />
<element signature="e#1119#1120#0" expanded="true" />
<element signature="e#1160#1161#0" expanded="true" />
<element signature="e#1196#1197#0" expanded="true" />
<element signature="e#1241#1242#0" expanded="true" />
<element signature="e#1191#1192#0" expanded="true" />
<element signature="e#1232#1233#0" expanded="true" />
<element signature="e#1520#1521#0" expanded="true" />
<element signature="e#1551#1552#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/adder/tests/integration_test.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="96">
<caret line="6" column="20" selection-start-line="6" selection-start-column="20" selection-end-line="6" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/adder/tests/common/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="48">
<caret line="3" lean-forward="true" selection-start-line="3" selection-end-line="3" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
@ -77,6 +107,9 @@
<option value="$PROJECT_DIR$/generics/src/point.rs" />
<option value="$PROJECT_DIR$/generics/src/lib.rs" />
<option value="$PROJECT_DIR$/lifetimes/src/main.rs" />
<option value="$PROJECT_DIR$/adder/src/lib.rs" />
<option value="$PROJECT_DIR$/adder/tests/common/mod.rs" />
<option value="$PROJECT_DIR$/adder/tests/integration_test.rs" />
</list>
</option>
</component>
@ -110,13 +143,20 @@
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="lifetimes" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="adder" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="lifetimes" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="src" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="adder" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="tests" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
<path>
<item name="rust" type="3d21c010:ScopeViewTreeModel$ProjectNode" />
<item name="rust" type="2674bda8:ScopeViewTreeModel$GroupNode" />
<item name="adder" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="tests" type="9f88c78c:ScopeViewTreeModel$FileNode" />
<item name="common" type="9f88c78c:ScopeViewTreeModel$FileNode" />
</path>
</expand>
<select />
@ -149,7 +189,7 @@
</component>
<component name="PropertiesComponent">
<property name="JavaScriptWeakerCompletionTypeGuess" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1548960808738" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1548965323798" />
<property name="javascript.nodejs.core.library.configured.version" value="7.1.0" />
<property name="js.eslint.eslintPackage" value="$USER_HOME$/.yarn-config/global/node_modules/.bin/eslint" />
<property name="js.eslint.nodeInterpreter" value="project" />
@ -177,7 +217,7 @@
</list>
</option>
</component>
<component name="RunManager" selected="Cargo Command.Run lifetimes">
<component name="RunManager" selected="Cargo Command.Test lib::tests">
<configuration name="&lt;template&gt;" type="TestNG" default="true" selected="false">
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" value="-ea" />
@ -196,36 +236,6 @@
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Run errors" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package errors --bin errors" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/errors" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run generics" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package generics --bin generics" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/generics" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run largest_number" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package largest_number --bin largest_number" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/largest_number/src" />
<envs />
<method v="2" />
</configuration>
<configuration name="Run lifetimes" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package lifetimes --bin lifetimes" />
@ -236,13 +246,43 @@
<envs />
<method v="2" />
</configuration>
<configuration name="Run modules" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<configuration name="Test lib::tests" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="run --package modules --bin modules" />
<option name="command" value="test --package adder --lib tests" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/modules" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/adder" />
<envs />
<method v="2" />
</configuration>
<configuration name="Test tests::greater_than_100" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package adder --lib tests::greater_than_100 -- --exact" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/adder" />
<envs />
<method v="2" />
</configuration>
<configuration name="Test tests::greeting_contains_name" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package adder --lib tests::greeting_contains_name -- --exact" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/adder" />
<envs />
<method v="2" />
</configuration>
<configuration name="Test tests::it_works" type="CargoCommandRunConfiguration" factoryName="Cargo Command" temporary="true">
<option name="channel" value="DEFAULT" />
<option name="command" value="test --package adder --lib tests::it_works -- --exact" />
<option name="allFeatures" value="false" />
<option name="nocapture" value="false" />
<option name="backtrace" value="SHORT" />
<option name="workingDirectory" value="file://$PROJECT_DIR$/adder" />
<envs />
<method v="2" />
</configuration>
@ -255,20 +295,40 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Cargo Command.Test lib::tests" />
<item itemvalue="Cargo Command.Test tests::greater_than_100" />
<item itemvalue="Cargo Command.Test tests::greeting_contains_name" />
<item itemvalue="Cargo Command.Test tests::it_works" />
<item itemvalue="Cargo Command.Run lifetimes" />
<item itemvalue="Cargo Command.Run generics" />
<item itemvalue="Cargo Command.Run largest_number" />
<item itemvalue="Cargo Command.Run errors" />
<item itemvalue="Cargo Command.Run modules" />
</list>
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="Test_tests__it_works - 2019.01.31 at 14h 06m 37s.xml">
<configuration name="Test tests::it_works" configurationId="CargoCommandRunConfiguration" />
</history-entry>
<history-entry file="Test_tests__greeting_contains_name - 2019.01.31 at 14h 18m 57s.xml">
<configuration name="Test tests::greeting_contains_name" configurationId="CargoCommandRunConfiguration" />
</history-entry>
<history-entry file="Test_tests__greeting_contains_name - 2019.01.31 at 14h 19m 31s.xml">
<configuration name="Test tests::greeting_contains_name" configurationId="CargoCommandRunConfiguration" />
</history-entry>
<history-entry file="Test_lib__tests - 2019.01.31 at 14h 20m 55s.xml">
<configuration name="Test lib::tests" configurationId="CargoCommandRunConfiguration" />
</history-entry>
<history-entry file="Test_tests__greater_than_100 - 2019.01.31 at 14h 21m 34s.xml">
<configuration name="Test tests::greater_than_100" configurationId="CargoCommandRunConfiguration" />
</history-entry>
<history-entry file="Test_lib__tests - 2019.01.31 at 14h 59m 57s.xml">
<configuration name="Test lib::tests" configurationId="CargoCommandRunConfiguration" />
</history-entry>
</component>
<component name="ToolWindowManager">
<frame x="1680" y="-410" width="1050" height="1657" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" sideWeight="0.49724266" visible="true" weight="0.26141885" />
<window_info id="Structure" order="1" sideWeight="0.5027574" side_tool="true" visible="true" weight="0.26141885" />
<window_info active="true" content_ui="combo" id="Project" order="0" sideWeight="0.49663138" visible="true" weight="0.26141885" />
<window_info id="Structure" order="1" sideWeight="0.5033686" side_tool="true" visible="true" weight="0.26141885" />
<window_info id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
<window_info id="Capture Tool" order="4" />
@ -276,7 +336,7 @@
<window_info id="Cargo" order="6" sideWeight="0.49791494" weight="0.3286119" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32979318" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.29761136" />
<window_info anchor="bottom" id="Run" order="2" weight="0.29761136" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
@ -284,7 +344,7 @@
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Inspection Results" order="9" weight="0.32979318" />
<window_info anchor="bottom" id="Terminal" order="10" weight="0.32924467" />
<window_info anchor="bottom" id="Terminal" order="10" visible="true" weight="0.32924467" />
<window_info anchor="bottom" id="Event Log" order="11" side_tool="true" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
@ -529,5 +589,42 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/adder/src/lib.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1025">
<caret line="66" column="5" selection-start-line="66" selection-start-column="5" selection-end-line="66" selection-end-column="5" />
<folding>
<element signature="e#251#252#0" expanded="true" />
<element signature="e#263#264#0" expanded="true" />
<element signature="e#304#305#0" expanded="true" />
<element signature="e#338#339#0" expanded="true" />
<element signature="e#1036#1037#0" expanded="true" />
<element signature="e#1077#1078#0" expanded="true" />
<element signature="e#1119#1120#0" expanded="true" />
<element signature="e#1160#1161#0" expanded="true" />
<element signature="e#1196#1197#0" expanded="true" />
<element signature="e#1241#1242#0" expanded="true" />
<element signature="e#1191#1192#0" expanded="true" />
<element signature="e#1232#1233#0" expanded="true" />
<element signature="e#1520#1521#0" expanded="true" />
<element signature="e#1551#1552#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/adder/tests/common/mod.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="48">
<caret line="3" lean-forward="true" selection-start-line="3" selection-end-line="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/adder/tests/integration_test.rs">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="96">
<caret line="6" column="20" selection-start-line="6" selection-start-column="20" selection-end-line="6" selection-end-column="20" />
</state>
</provider>
</entry>
</component>
</project>

7
adder/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "adder"
version = "0.1.0"
authors = ["Timothy Warren <twarren@nabancard.com>"]
edition = "2018"
[dependencies]

104
adder/src/lib.rs Normal file
View File

@ -0,0 +1,104 @@
#[derive(Debug)]
pub struct Rectangle {
length: u32,
width: u32,
}
impl Rectangle {
pub fn can_hold(&self, other: &Rectangle) -> bool {
self.length > other.length && self.width > other.width
}
}
pub fn add_two(a: i32) -> i32 {
a + 2
}
pub fn greeting(name: &str) -> String {
format!("Hello, {}!", name)
}
pub struct Guess {
value: i32,
}
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!("Guess value must be greater than or equal to 1, got {}.",
value);
} else if value > 100 {
panic!("Guess value must be less than or equal to 100, got {}.",
value);
}
Guess {
value
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn it_works() -> Result<(), String> {
if 2 + 2 == 4 {
Ok(())
} else {
Err(String::from("two plus two does not equal four"))
}
}
#[test]
fn add_two_and_two() {
assert_eq!(4, add_two(2));
}
#[test]
fn add_three_and_two() {
assert_eq!(5, add_two(3));
}
#[test]
fn one_hundred() {
assert_eq!(102, add_two(100));
}
#[test]
fn larger_can_hold_smaller() {
let larger = Rectangle { length: 8, width: 7 };
let smaller = Rectangle { length: 5, width: 1 };
assert!(larger.can_hold(&smaller));
}
#[test]
fn smaller_cannot_hold_larger() {
let larger = Rectangle { length: 8, width: 7 };
let smaller = Rectangle { length: 5, width: 1 };
assert!(!smaller.can_hold(&larger));
}
#[test]
fn it_adds_two() {
assert_eq!(4, add_two(2));
}
#[test]
fn greeting_contains_name() {
let result = greeting("Carol");
assert!(
result.contains("Carol"),
"Greeting did not contain name, value was `{}`", result
);
}
#[test]
#[should_panic(expected = "Guess value must be less than or equal to 100")]
fn greater_than_100() {
Guess::new(200);
}
}

View File

@ -0,0 +1,3 @@
pub fn setup() {
// setup code specific to your library's tests would go here
}

View File

@ -0,0 +1,9 @@
use adder;
mod common;
#[test]
fn it_adds_two() {
common::setup();
assert_eq!(4, adder::add_two(2));
}