{"id":169,"date":"2021-01-21T16:46:48","date_gmt":"2021-01-21T16:46:48","guid":{"rendered":"https:\/\/kenpugh.com\/blog\/?p=169"},"modified":"2021-04-26T18:40:32","modified_gmt":"2021-04-26T18:40:32","slug":"layers-of-scenarios-and-a-reply-on-randomness","status":"publish","type":"post","link":"https:\/\/kenpugh.com\/blog\/layers-of-scenarios-and-a-reply-on-randomness\/","title":{"rendered":"Layers of Scenarios and a Reply on Randomness"},"content":{"rendered":"<p><strong>\u00a0<\/strong><\/p>\n<p>Gojko Adzic asked for opinions in his blog \u201c<a href=\"https:\/\/specflow.org\/blog\/how-to-specify-that-something-should-be-random-givenwhenthenwithstyle\/\">How to Specify Something Should Be Random<\/a>.\u00a0 He presented alternative scenarios and asked for your choice.<\/p>\n<p>The situation he described is having a robot\u2019s chat response appear like it comes from a human being. There could be multiple levels of tests associated with this requirement. Let\u2019s take a look at these levels and along the way give my choice(s) for an answer.<!--more--><\/p>\n<p>Let\u2019s start with a high level scenario for the functionality itself:<\/p>\n<pre>Scenario: Robot types reply that seems like it was typed by a human\nGiven a robot receives a message\nWhen the robot types a reply\nThen the reply has characteristics that mimic a human being<\/pre>\n<p>There may be some exploration associated with this scenario to determine what those characteristics are. They could include pauses between characters, backspacing, quick word completion (simulating auto completion) and so forth. This scenario might be tested manually. The bot would type a response and then a human would state whether it look \u201crobotish\u201d or \u201chumanish\u201d. Suppose it was determined that pauses were a characteristic to be implemented:<\/p>\n<pre>Scenario: Robot types reply that has pauses\nGiven a robot receives a message\nWhen the robot types a reply\nThen the reply has pauses that mimic a human being<\/pre>\n<p>For some teams, this might be enough. The timing of the pauses would be handled in the implementation. For others more detail could be included that describes what particularly mimics a human being. This would specify the results of the exploration.<\/p>\n<pre>Scenario: Robot types reply that has random pauses\nGiven a robot receives a message\nWhen the robot types a reply\nThen the reply has pauses between characters that randomly vary between 0.2 and 0.5 seconds<\/pre>\n<p>Testing this scenario would probably require automation to measure the delays between characters appearing on the screen. The test would just check that the pauses fell within that range and that they were not all the same.<\/p>\n<p>One tricky issue is the meaning of random. Checking randomness involves technical tests. Wikipedia has some details on <a href=\"https:\/\/en.wikipedia.org\/wiki\/Randomness_test\">randomness tests.<\/a>\u00a0 These tests check that a sequence is random to some level of confidence.<\/p>\n<p>At the high level, the randomness could be checked by using a large number of replies and testing the set of pauses that were inserted in the replies.<\/p>\n<pre>Scenario: Robot types random pauses over a large set of replies\nGiven a large set of replies\nWhen the robot types them\nThen pauses between characters are random with a confidence level of 99%<\/pre>\n<p>Now this scenario and the previous one cover the external behavior for the requirement. In answer to Gojko\u2019s question, I would have both of these scenarios to cover the requirement. They represent behavior that is externally visible.<\/p>\n<p><strong>Randomness <\/strong><\/p>\n<p>As an internal test, one could run the randomness tests against the method that produced a random sequence, if the creator had not already done so.<\/p>\n<pre>Scenario: Given a pseudo random number generator that produces values from 0.0 to 1.0\nWhen a long sequence is produced\nThen it is random with a confidence level of 99%<\/pre>\n<p>As a general rule, values that are random should have a test double (mock) that produces a known output for testing. These values for the test double can be setup in a Given. For example, here\u2019s a test that checks the conversion to a range is correct:<\/p>\n<pre>Scenario: Convert random sequence to pause sequence\nGiven random sequence &lt;value&gt;\nWhen converted to pause from 0.2 to 0.5\nThen pause length is &lt;length&gt;\n| value | length | Notes |\n| 1.0 | .5 s     | maximum |\n| 0.9 | .47 s    |\n| 0.4 | .32 s    |\n| 0.6 | .38 s    |\n| 0.0 | .2 s     | minimum |<\/pre>\n<p>Another internal test could check the plumbing between the pause sequence method and the reply functionality.<\/p>\n<pre>Scenario: Check that random sequence produces appropriate pauses\nGiven random sequence is:\n| value |\n| 1.0   |\n| 0.9   |\n| 0.4   |\n| 0.6   |\n| 0.0   |\nWhen bot replies \u201chello\u201d\nThen the pauses between character are:\n| char | pause |\n| H    | .5 s  |\n| e    | .47 s |\n| l    | .32 s |\n| l    | .38 s |\n| o    | .2 s  |\n\n<strong>Summary<\/strong><\/pre>\n<p>I suggest you have at least the two external scenarios that show a single reply and also check randomness on a series of replies. Depending on the complexity of the implementation, you might have the other scenarios as internal tests for methods or combinations of methods.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Gojko Adzic asked for opinions in his blog \u201cHow to Specify Something Should Be Random.\u00a0 He presented alternative scenarios and asked for your choice. The situation he described is having a robot\u2019s chat response appear like it comes from a human being. There could be multiple levels of tests associated with this requirement. Let\u2019s &hellip; <a href=\"https:\/\/kenpugh.com\/blog\/layers-of-scenarios-and-a-reply-on-randomness\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Layers of Scenarios and a Reply on Randomness<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10,6,7],"class_list":["post-169","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-atdd","tag-bdd","tag-scenarios"],"_links":{"self":[{"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/posts\/169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/comments?post=169"}],"version-history":[{"count":4,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/posts\/169\/revisions\/186"}],"wp:attachment":[{"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/media?parent=169"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/categories?post=169"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kenpugh.com\/blog\/wp-json\/wp\/v2\/tags?post=169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}