|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +test_dir="tmp" |
| 4 | +dir=({1..10}.jpg {1..10}.png {1..10}.doc {1..10}.docx {1..10}.pdf {1..10}.csv {1..10}.sh {1..10}.tar.bz2 {1..10}.pptx {1..10}.mp3 {1..10}.mp4 {1..10}.unknown) |
| 5 | + |
| 6 | +function set_up() { |
| 7 | + mkdir "$test_dir" |
| 8 | + |
| 9 | + for file in "${dir[@]}"; do |
| 10 | + touch "$test_dir/$file" |
| 11 | + done |
| 12 | +} |
| 13 | + |
| 14 | +function tear_down() { |
| 15 | + for file in "${dir[@]}"; do |
| 16 | + rm "$test_dir/$file" |
| 17 | + done |
| 18 | + |
| 19 | + rmdir "$test_dir" |
| 20 | +} |
| 21 | + |
| 22 | +function test_cant_organise_unknown_files() { |
| 23 | + local unknown_files=($(ls "$test_dir"/*.unknown)) |
| 24 | + assert_equals "${#unknown_files[@]}" "10" |
| 25 | +} |
| 26 | + |
| 27 | +function test_can_organise_images() { |
| 28 | + local images=($(ls "$test_dir"/*.{jpg,png})) |
| 29 | + assert_equals "${#images[@]}" "$((10*2))" |
| 30 | +} |
| 31 | + |
| 32 | +function test_can_organise_documents() { |
| 33 | + local docs=($(ls "$test_dir"/*.{doc,docx,pdf})) |
| 34 | + assert_equals "${#docs[@]}" "$((10*3))" |
| 35 | +} |
| 36 | + |
| 37 | +function test_can_organise_spreadsheets() { |
| 38 | + local csv_files=($(ls "$test_dir"/*.csv)) |
| 39 | + assert_equals "${#csv_files[@]}" "10" |
| 40 | +} |
| 41 | + |
| 42 | +function test_can_organise_scripts() { |
| 43 | + local scripts=($(ls "$test_dir"/*.sh)) |
| 44 | + assert_equals "${#scripts[@]}" "10" |
| 45 | +} |
| 46 | + |
| 47 | +function test_can_organise_archives() { |
| 48 | + local archives=($(ls "$test_dir"/*.tar.bz2)) |
| 49 | + assert_equals "${#archives[@]}" "10" |
| 50 | +} |
| 51 | + |
| 52 | +function test_can_organise_presentations() { |
| 53 | + local presentations=($(ls "$test_dir"/*.pptx)) |
| 54 | + assert_equals "${#presentations[@]}" "10" |
| 55 | +} |
| 56 | + |
| 57 | +function test_can_organise_audio_files() { |
| 58 | + local audio_files=($(ls "$test_dir"/*.mp3)) |
| 59 | + assert_equals "${#audio_files[@]}" "10" |
| 60 | +} |
| 61 | + |
| 62 | +function test_can_organise_video_files() { |
| 63 | + local video_files=($(ls "$test_dir"/*.mp4)) |
| 64 | + assert_equals "${#video_files[@]}" "10" |
| 65 | +} |
| 66 | + |
0 commit comments