-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapstone.yml
110 lines (81 loc) · 3.69 KB
/
capstone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: fortune
title: Fortune
is_published: true
short_description: Implement the famous <em>fortune</em> command of Unix in Python.
description: |
Implement a simple version of popular Unix program [fortune][1] in Python.
[1]: https://en.wikipedia.org/wiki/Fortune_(Unix)
The fortune program prints a quote selected at random from a quotes file.
tags: []
tasks:
- name: clone-repository
title: Clone Git repository with starter code
description: |
Get started by cloning the Git repository. This will have the starter code you will build upon.
Your progress will get updated when you push to this repository.
```
git clone {git_url}
```
checks:
- name: check_fortune_working
title: Check fortune.py is present and working
args:
command: python fortune.py
- name: print-a-random-quote
title: Print a Random Quote
description: |
Print a quote from the fortune file at path `files/fortune.txt` selected at random.
**The Fortune File Format**
The fortune file is a simple text based file format containing multiple quotes seperated by a `%` character. in a new line.
The following example is a simple fortune file with three quotes. As you can see the quotes are seperated by a line containing `%` character.
```
When in dount, use brute force.
-- Ken Thompson, Bell Labs
%
Electricity travels a foot in a nano second.
-- Commodore Grace Murray Hopper, United States Navy
%
[Brook's Law of Prototypes] Plan to throw one away, you will any how.
-- Fred Brooks, University of North Carolina
```
**Your Task**
Your task is to parse the fortune file, select one of the quotes at random and print it. Go for it!
checks:
- name: check_fortune_working
title: Check fortune.py is present and working
args: {}
- name: check_fortune_random
title: Check if fortune.py is printing a random quote
args: {}
- name: option-f
title: Custom fortune file using -f option
description: |
Add a command-line option `-f` to specify a custom fortune file.
When this option is specified, the program will print a quote from the specified file instead of the default fortune file.
For example, when we specify `-f files/einstein.txt`, it prints one of the quotes by Albert Einstein.
```
$ python fortune.py -f files/einstein.txt
Imagination is more important than knowledge.
-- Albert Einstein
```
checks:
- name: check_fortune_is_from_file
title: Check fortune.py without -f
args: {}
- name: check_fortune_is_from_file
title: Check fortune.py with -f files/einstein.txt
args:
fortune_file: files/einstein.txt
# Task 1: print a quote.
# print the first line of the quotes file. Assume the quotes file is at path quotes.txt
# Task 2: print a quote at random
# Parse the quotes file and pick one quote at random.
# Task 3: custom quotes file
# provide an ability to specify a custom quotes file using option -f
# Task 4: custom quotes file using environment
# Support specifying quotes file using environment variable FORTUNE_FILE.
# When both environment variable and -f flag are specified, the command line flag takes precedence.
# Task 5: Short quotes
# Add support for printing only a short quote when command-line option -s is used. When the -s option is used, only the quotes that have length not more than 100 are considered.
# Task 6: quote length
# The -s flag considers only quotes that are not longer than 100. Support a command-line flag -n to specify the maximum length allowed for short quotes.