123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package.path = "../?.lua;" .. package.path
- local MarkovGraph = require("markov_chains")
- describe("markov_chains", function()
-
- local graph = MarkovGraph()
- local graph2 = MarkovGraph()
- local trainingstr = "abc def ghi"
- it("repeats", function()
- graph:learn_line(trainingstr)
- assert.equals(trainingstr, graph:get_sentence())
- end)
- it("randomizes", function()
- graph:learn_line("abc ghi")
- graph:learn_line("def abc abc ghi def")
- local random = false
- for i = 1, 10
- do
- random = random or graph:get_sentence() ~= trainingstr
- end
- assert(random)
- assert.equals("number", type(math.huge))
- end)
- it("culls", function()
- assert.equals(3, graph:count_known_words())
- graph:cull(2)
- assert(graph:count_known_words() <= 2, "Doesn't cull to max size!")
- end)
- it("learns from file", function()
- local graph = MarkovGraph()
- graph:learn_from_file("tests/test_resource_learner.txt")
- assert.equals(8, graph:count_known_words())
- end)
-
-
- it("stores words seperately for each graph", function()
- assert.equals(0, graph2:count_known_words())
- end)
- it("can learn from each other", function()
- local graph = MarkovGraph()
- graph:learn_from_file("tests/test_resource_learner.txt")
- graph2:learn_line(graph:get_sentence())
- assert(graph2:count_known_words() ~= 0)
- end)
-
- it("culls the least used", function()
- local graph = MarkovGraph()
- graph:learn_line("abc abc def")
- graph:learn_line("abc")
- assert.equals(2, graph:count_known_words())
- graph:cull(1)
- assert.equals(1, graph:count_known_words())
- graph:learn_line("def")
- assert.equals(2, graph:count_known_words())
-
- end)
-
- it("culls circles", function()
- local graph = MarkovGraph()
- graph:learn_line("it is the elephant's fault is")
- graph:learn_line("it is de elefnts falt as")
- assert.equals(9, graph:count_known_words())
- graph:cull(5)
- assert.equals(5, graph:count_known_words())
- end)
- end)
|