From afec5a7e05a9960b1f60be44a77fda8f771c9504 Mon Sep 17 00:00:00 2001 From: Tyler Wardhaugh Date: Sat, 10 Oct 2020 22:58:01 -0700 Subject: Ch81 [Lua]: Tasks 1 & 2 I used LPeg for both of these solutions, which is surely overkill. But I wanted to experiment with it. --- challenge-081/tyler-wardhaugh/lua/test.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100755 challenge-081/tyler-wardhaugh/lua/test.lua (limited to 'challenge-081/tyler-wardhaugh/lua/test.lua') diff --git a/challenge-081/tyler-wardhaugh/lua/test.lua b/challenge-081/tyler-wardhaugh/lua/test.lua new file mode 100755 index 0000000000..0874b984cc --- /dev/null +++ b/challenge-081/tyler-wardhaugh/lua/test.lua @@ -0,0 +1,25 @@ +#!/usr/bin/env lua + +require 'busted.runner'() + +describe("Task 1, Common Base String", function() + local t1 = require'ch-1' + it("produces correct results for the examples", function() + assert.are.same(t1.common_base_string("abcdabcd", "abcdabcdabcdabcd"), {"abcdabcd", "abcd"}) + assert.are.same(t1.common_base_string("aaa", "aa"), {"a"}) + end) +end) + +describe("Task 2, Frequency Sort", function() + local t2 = require'ch-2' + it("produces correct results for the examples", function() + local expected = { + [1]={"But", "City", "It", "Jet", "Juliet", "Latino", "New", "Romeo", "Side", "Story", "Their", "Then", "West", "York", "adaptation", "any", "anything", "at", "award-winning", "away", "become", "before", "begin", "best", "classic", "climactic", "coexist", "control", "dance", "do", "doesn't", "end", "ending", "escalates", "families", "feuding", "form", "former", "friend", "gains", "gangs", "goes", "happened", "hatred", "heartbreaking", "highway", "hoping", "in", "know", "love", "lovers", "meet", "meeting", "neither", "no", "one", "plan", "planning", "point", "romantic", "rumble", "run", "secret", "sends", "sister", "streets", "strikes", "terribly", "their", "two", "under", "understanding", "until", "violence", "warring", "what", "when", "where", "white", "whoever", "wins", "with", "wrong", "younger"}, + [2]={"Bernardo", "Jets", "Riff", "Sharks", "The", "by", "it", "led", "tragedy"}, + [3]={"Maria", "Tony", "a", "can", "of", "stop"}, + [4]={"to"}, + [9]={"and", "the"} + } + assert.are.same(t2.frequency_sort(t2.slurp("resources/input")), expected) + end) +end) -- cgit