|
@@ -1,29 +1,47 @@
|
|
Some tests building a simple API that determines whether an input string contains every lower-case character in the latin alphabet
|
|
Some tests building a simple API that determines whether an input string contains every lower-case character in the latin alphabet
|
|
|
|
|
|
-# Bash version
|
|
|
|
|
|
+# Bash (CGI) version
|
|
|
|
|
|
-Sample output
|
|
|
|
|
|
+### Check if POST'd string contains all lowercase letters of the latin alphabet
|
|
|
|
+**URL:** '/contains_all_chars.sh'
|
|
|
|
+**Method:** POST
|
|
|
|
+**Data params:** Plain text
|
|
|
|
+**Details:** Removes all non-interesting characters, sorts remaining characters, removes duplicates. Checks that the length of the result matches the length of the characters we wanted.
|
|
|
|
|
|
|
|
+**Example response:**
|
|
|
|
+```
|
|
|
|
+{ "error": null, "result": True }
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+**Example use:**
|
|
```
|
|
```
|
|
# Sample string with all alphabet characters
|
|
# Sample string with all alphabet characters
|
|
[jceresini@slartibartfast ~]$ curl -X POST -d 'The quick brown fox jumps over the lazy dog' http://test.ceresini.com/contains_all_chars.sh
|
|
[jceresini@slartibartfast ~]$ curl -X POST -d 'The quick brown fox jumps over the lazy dog' http://test.ceresini.com/contains_all_chars.sh
|
|
-
|
|
|
|
{"error": null, "result": true}
|
|
{"error": null, "result": true}
|
|
|
|
|
|
# Sample string that doesn't contain all alphabet characters
|
|
# Sample string that doesn't contain all alphabet characters
|
|
[jceresini@slartibartfast ~]$ curl -X POST -d 'This string does not contain many letters of the alphabet' http://test.ceresini.com/contains_all_chars.sh
|
|
[jceresini@slartibartfast ~]$ curl -X POST -d 'This string does not contain many letters of the alphabet' http://test.ceresini.com/contains_all_chars.sh
|
|
-
|
|
|
|
{"error": null, "result": false}
|
|
{"error": null, "result": false}
|
|
|
|
|
|
# Hitting API endpoint with GET method
|
|
# Hitting API endpoint with GET method
|
|
[jceresini@slartibartfast ~]$ curl http://test.ceresini.com/contains_all_chars.sh
|
|
[jceresini@slartibartfast ~]$ curl http://test.ceresini.com/contains_all_chars.sh
|
|
-
|
|
|
|
{"error": "Invalid http method", "result": null}
|
|
{"error": "Invalid http method", "result": null}
|
|
```
|
|
```
|
|
|
|
|
|
-# Python version
|
|
|
|
|
|
+# Python version using Flask
|
|
|
|
+
|
|
|
|
+### Check if POST'd string contains all lowercase letters of the latin alphabet: Method A
|
|
|
|
+**URL:** '/contains_all_chars_a'
|
|
|
|
+**Method:** POST
|
|
|
|
+**Data params:** Plain text
|
|
|
|
+**Details:** Uses python's built-in [set].issubset function to see if the set of lowercase latin alphabet characters is a subset of the posted data
|
|
|
|
|
|
-## Simplified call using sets
|
|
|
|
|
|
+**Example response:**
|
|
|
|
+```
|
|
|
|
+{ "error": null, "result": True }
|
|
|
|
+```
|
|
|
|
+
|
|
|
|
+**Example use:**
|
|
```
|
|
```
|
|
[jceresini@slartibartfast]$ curl -H "Content-type: text/plain" -d "@testfiles/doi.txt" http://test.ceresini.com:5000/contains_all_chars_a
|
|
[jceresini@slartibartfast]$ curl -H "Content-type: text/plain" -d "@testfiles/doi.txt" http://test.ceresini.com:5000/contains_all_chars_a
|
|
{"result": true, "error": null}
|
|
{"result": true, "error": null}
|
|
@@ -35,8 +53,18 @@ Sample output
|
|
{"result": false, "error": null}
|
|
{"result": false, "error": null}
|
|
```
|
|
```
|
|
|
|
|
|
|
|
+### Check if POST'd string contains all lowercase letters of the latin alphabet: Method B
|
|
|
|
+**URL:** '/contains_all_chars_a'
|
|
|
|
+**Method:** POST
|
|
|
|
+**Data params:** Plain text
|
|
|
|
+**Details:** Interates over each character of the posted data to see if it contains each lowercase character in the latin alphabet. Returns as soon as it has seen each character once.
|
|
|
|
+
|
|
|
|
+**Example response:**
|
|
|
|
+```
|
|
|
|
+{ "error": null, "result": True }
|
|
|
|
+```
|
|
|
|
|
|
-## Slower call iterating over the input string
|
|
|
|
|
|
+**Example use:**
|
|
```
|
|
```
|
|
[jceresini@slartibartfast]$ curl -H "Content-type: text/plain" -d "@testfiles/doi.txt" http://test.ceresini.com:5000/contains_all_chars_b
|
|
[jceresini@slartibartfast]$ curl -H "Content-type: text/plain" -d "@testfiles/doi.txt" http://test.ceresini.com:5000/contains_all_chars_b
|
|
{"result": true, "error": null}
|
|
{"result": true, "error": null}
|