add two-fer exercise (#18)

* add two-fer exercise

* fix
This commit is contained in:
Lars Hvam
2021-11-26 14:06:11 +01:00
committed by GitHub
parent 0011764f80
commit 2cd6a21348
8 changed files with 123 additions and 45 deletions

View File

@@ -349,27 +349,9 @@
"max_one_statement": true,
"message_exists": true,
"method_implemented_twice": true,
"method_length": {
"exclude": [],
"severity": "Error",
"statements": 100,
"errorWhenEmpty": true,
"ignoreTestClasses": false,
"checkForms": true
},
"method_length": false,
"method_overwrites_builtin": true,
"method_parameter_names": {
"exclude": [],
"severity": "Error",
"patternKind": "required",
"ignoreNames": [],
"ignorePatterns": [],
"ignoreExceptions": true,
"importing": "^I._.+$",
"returning": "^R._.+$",
"changing": "^C._.+$",
"exporting": "^E._.+$"
},
"method_parameter_names": false,
"mix_returning": true,
"modify_only_own_db_tables": {
"exclude": [],
@@ -550,11 +532,7 @@
"severity": "Error",
"skipNames": []
},
"unused_variables": {
"exclude": [],
"severity": "Error",
"skipNames": []
},
"unused_variables": false,
"use_bool_expression": true,
"use_class_based_exceptions": true,
"use_line_exists": true,

View File

@@ -349,27 +349,9 @@
"max_one_statement": true,
"message_exists": true,
"method_implemented_twice": true,
"method_length": {
"exclude": [],
"severity": "Error",
"statements": 100,
"errorWhenEmpty": true,
"ignoreTestClasses": false,
"checkForms": true
},
"method_length": false,
"method_overwrites_builtin": true,
"method_parameter_names": {
"exclude": [],
"severity": "Error",
"patternKind": "required",
"ignoreNames": [],
"ignorePatterns": [],
"ignoreExceptions": true,
"importing": "^I._.+$",
"returning": "^R._.+$",
"changing": "^C._.+$",
"exporting": "^E._.+$"
},
"method_parameter_names": false,
"mix_returning": true,
"modify_only_own_db_tables": {
"exclude": [],

View File

@@ -28,6 +28,14 @@
"practices": [],
"prerequisites": [],
"difficulty": 1
},
{
"slug": "two-fer",
"name": "Two Fer",
"uuid": "4606da73-f376-409e-8526-f95bec03643b",
"practices": [],
"prerequisites": [],
"difficulty": 1
}
]
},

View File

@@ -0,0 +1,26 @@
# Description
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
Given a name, return a string with the message:
```text
One for name, one for me.
```
Where "name" is the given name.
However, if the name is missing, return the string:
```text
One for you, one for me.
```
Here are some examples:
|Name |String to return
|:-------|:------------------
|Alice |One for Alice, one for me.
|Bob |One for Bob, one for me.
| |One for you, one for me.
|Zaphod |One for Zaphod, one for me.

View File

@@ -0,0 +1,12 @@
{
"blurb": "Create a sentence of the form \"One for X, one for me.\".",
"authors": ["larshp"],
"contributors": [
],
"files": {
"solution": ["zcl_two_fer.clas.abap"],
"test": ["zcl_two_fer.clas.testclasses.abap"],
"example": [".meta/zcl_two_fer.clas.abap"]
},
"source_url": "https://github.com/exercism/problem-specifications/issues/757"
}

View File

@@ -0,0 +1,20 @@
CLASS zcl_two_fer DEFINITION PUBLIC.
PUBLIC SECTION.
METHODS two_fer
IMPORTING
input TYPE string OPTIONAL
RETURNING
VALUE(result) TYPE string.
ENDCLASS.
CLASS zcl_two_fer IMPLEMENTATION.
METHOD two_fer.
DATA(name) = input.
IF name IS INITIAL.
name = 'you'.
ENDIF.
result = |One for { name }, one for me.|.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,16 @@
CLASS zcl_two_fer DEFINITION PUBLIC.
PUBLIC SECTION.
METHODS two_fer
IMPORTING
input TYPE string OPTIONAL
RETURNING
VALUE(result) TYPE string.
ENDCLASS.
CLASS zcl_two_fer IMPLEMENTATION.
METHOD two_fer.
* add solution here
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,36 @@
CLASS ltcl_two_fer DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.
PRIVATE SECTION.
DATA cut TYPE REF TO zcl_two_fer.
METHODS setup.
METHODS test_empty FOR TESTING RAISING cx_static_check.
METHODS test_alice FOR TESTING RAISING cx_static_check.
METHODS test_bob FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS ltcl_two_fer IMPLEMENTATION.
METHOD setup.
cut = NEW zcl_two_fer( ).
ENDMETHOD.
METHOD test_empty.
cl_abap_unit_assert=>assert_equals(
act = cut->two_fer( )
exp = 'One for you, one for me.' ).
ENDMETHOD.
METHOD test_alice.
cl_abap_unit_assert=>assert_equals(
act = cut->two_fer( 'Alice' )
exp = 'One for Alice, one for me.' ).
ENDMETHOD.
METHOD test_bob.
cl_abap_unit_assert=>assert_equals(
act = cut->two_fer( 'Bob' )
exp = 'One for Bob, one for me.' ).
ENDMETHOD.
ENDCLASS.