Skip to content
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

Rustlatin_new #175

Open
wants to merge 13 commits into
base: training_material_wip
Choose a base branch
from
84 changes: 68 additions & 16 deletions .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,89 @@
name: pages
on: [push, pull_request]
---

name: GitHub Pages
on:
# The website will be deployed when any of these branches is pushed to:
push:
branches:
- main
- training_material_wip
# Perform builds without uploads for pull requests:
pull_request:

jobs:
pages:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
branch:
- main
- training_material_wip

steps:
- name: Checkout repository
uses: actions/checkout@v1
uses: actions/checkout@v3
with:
ref: "${{ matrix.branch }}"

- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
bundler-cache: true

- name: Set up Node 16
uses: actions/setup-node@v3
with:
node-version: 16

- name: Install Dependencies
run: |
npm ci
gem install bundler
bundle install --jobs 4 --retry 3
- name: Install Node dependencies
run: npm ci

- name: Build
run: |
PATH="$(pwd)/node_modules/.bin:$PATH" ./rake
run: PATH="$(pwd)/node_modules/.bin:$PATH" ./rake

- name: Deploy
uses: ferrous-systems/shared-github-actions/github-pages@main
- name: Upload content
uses: actions/upload-artifact@v3
with:
name: "content-${{ matrix.branch }}"
path: target/
token: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
retention-days: 1

publish:
name: Publish
runs-on: ubuntu-latest

needs: [build]
if: github.event_name == 'push'

permissions:
pages: write
id-token: write

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}

steps:
- name: Download contents for the main branch
uses: actions/download-artifact@v3
with:
name: content-main
path: target/

- name: Download contents for the training_material_wip branch
uses: actions/download-artifact@v3
with:
name: content-training_material_wip
path: target/next/

- name: Upload GitHub Pages content
uses: actions/upload-pages-artifact@v1
with:
path: target/

- name: Deploy to GitHub Pages
uses: actions/deploy-pages@v1
id: deployment
7 changes: 7 additions & 0 deletions assignments/_templates/rustlatin/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions assignments/_templates/rustlatin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "rustlatin"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
30 changes: 30 additions & 0 deletions assignments/_templates/rustlatin/src/lib_1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const VOWELS: [char; 5] = ['a', 'e', 'i', 'o', 'u'];
// ^^^^^^^^^ The vowls are contained in an array, because the length never changes.
// It's a global const because it will not be modified in any way and only
// serves as a reference.

fn rustlatin(sentence: &str) -> Vec<_> {
// ^^^^^^^ The correct return type needs to be added by you,
// depending on what the vector's exact type is.

let mut collection_of_words = Vec::new();
// ^^^^^^^^^^^^ When you first open this file RA is not able to infer
// the type of this vector. Once you do the implementation,
// the type should appear here automatically.

// Your implementation goes here:
// Iterate over the sentence to split it into words.
// Push the words into the vector.
// Correct the return type of the vector


collection_of_words
}


#[test]
fn correct_splitting(){
assert_eq!(vec!["This", "sentence", "needs", "to", "be", "split"], rustlatin("This sentence needs to be split"))

}

21 changes: 21 additions & 0 deletions assignments/_templates/rustlatin/src/lib_2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const VOWELS: [char; 5] = ['a', 'e', 'i', 'o', 'u'];

fn rustlatin(sentence: &str) -> Vec<_> {
// ^^^^^^^ The correct return type needs to be added by you,
// depending on what the vector's exact type is.
let mut collection_of_words = Vec::new();

for word in sentence.split(' ') {
// Your implementation goes here:
// Add the suffix "rs" to each word before pushing it to the vector
// Correct the return type of the function.

};
collection_of_words
}

#[test]
fn concatenated(){
assert_eq!( vec!["dors", "yours", "likers", "rustrs"], rustlatin("do you like rust"))
}

22 changes: 22 additions & 0 deletions assignments/_templates/rustlatin/src/lib_3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const VOWELS: [char; 5] = ['a', 'e', 'i', 'o', 'u'];

fn rustlatin(sentence: &str) -> Vec<_> {
// ^^^^^^^ The correct return type needs to be added by you,
// depending on what the vector's exact type is.
let mut collection_of_chars = Vec::new();

for word in sentence.split(' ') {
// Your implementation goes here:
// Add the first char of each word to the vector.
// Correct the return type of the vector.

};
collection_of_chars
}


#[test]
fn return_the_char(){
assert_eq!(vec!['n', 't', 'd', 'b', 'i', 'a', 'r', 'v'], rustlatin("note the difference between iterator and return values"))
}

46 changes: 46 additions & 0 deletions assignments/_templates/rustlatin/src/lib_4.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

const VOWELS: [char; 5] = ['a', 'e', 'i', 'o', 'u'];

fn rustlatin(sentence: &str) -> String {

let mut collection_of_words = Vec::new();

for word in sentence.split(' ') {
let first_char = word.chars().next().unwrap();
// Your implementation goes here
// pushes the latinized words into the vector
};
collection_of_words.join(" ")
}

// fn latinize() goes here
// adds prefix "sr" and suffix "rs" according to the rules



#[test]
fn test_latinizer() {
assert_eq!(latinize("rust"), "rustrs");
assert_eq!(latinize("helps"), "helpsrs");
assert_eq!(latinize("you"), "yours");
assert_eq!(latinize("avoid"), "sravoid");

}

#[test]
fn correct_translation() {
// Why can we compare `&str` and `String` here?
// https://doc.rust-lang.org/stable/std/string/struct.String.html#impl-PartialEq%3C%26%27a%20str%3E
assert_eq!(
"rustrs helpsrs yours sravoid sra lotrs srof srirritating bugsrs",
rustlatin("rust helps you avoid a lot of irritating bugs")
)
}

#[test]
fn incorrect() {
assert_ne!(
"this shouldrs not workrs",
rustlatin("this should not work")
)
}
Loading