Valery V. Vorotyntsev ([info]vorotylo) wrote,
@ 2009-07-05 12:54:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
Entry tags:english, testing, work-log

"d-a-i" sequences explained

Well, the promised explanations.

The screenshot shows work-log.el debugging session. The "a-a-i-i-d" patchwork you see there is a work log model (more on this below). A work log is a sequence of dates, active entries, and inactive entries (the latter include comments); see example here. In short: resolved tasks == inactive, pending ones == active, that's it.

Now. `work-log-hide-inactive' function (`C-c C-h') lets user concentrate on open tasks, making inactive "noise" invisible.

The first implementation of the hiding function did hide resolved tasks but also left some dates with no entries at all hanging void. Like this:

2009-07-03

  http://lib/it/processMMS: update scenarios' table

2009-07-02

2009-07-01

  import `recsep' to CVS

Note the "hanging" 2009-07-02.

Okay. Let's omit the boring details (head scratching, pencil sketching, and a couple of "aha!" moments) and goto right to the way I debugged the damn function...

Here the simplified model of a work log suffice: a "d-a-i" sequence -- sequence of ['d', 'a', 'i', '-'] characters, where 'd' represents date, 'a' -- active entry, and 'i' -- inactive. Hyphen ('-') is either empty line or the continuation of previous entry (a task entry in real log can consist of several lines).

All we need to do is change a bit the hiding function (substitute regexps, replace `forward-line' with `forward-char', and show the "hidden" regions in inverted color instead of actually hiding them) and run it on a bunch of dai-sequences.

Testing input is easy to generate:

import Data.List (permutations)

main = putStrLn $ concatMap (\(x,y) -> x++y) (xs `zip` repeat "-")
    where xs = concat $ permutations ["a", "a", "i", "i", "d"]

Given "i-d-a-d-i-d-a-i-" we get:

i-d-a-d-i-d-a-i-

Do you see a hanging date? The hidden (black) region in the middle should cover preceding date ('d-') but it does not.

Well, you got the idea. Once the testing routine was established, it was easy to fix the bug.

i-d-a-d-i-d-a-i-

Q.E.D.

* * *

Yes, and while you're here, I'd like to recommend this post:
Benefits of automated functional testing (was: Why unit testing is a waste of time)

Have fun!




(2 comments) - (Post a new comment)


[info]thesz
2009-07-05 12:00 pm UTC (link)
Sorry, didn't catch anything at all.

По-русски можно?

(Reply to this) (Thread)


[info]vorotylo
2009-07-05 01:54 pm UTC (link)
Конечно нельзя, Серж. Не буду же переписывать всю эту фигню ещё раз! :)

Могу переформулировать "на пальцах". Итак, есть текстовый файл, форматом похожий на смесь ChangeLog с TODO. Есть Emacs mode, который синтаксически подсвечивает этот файл, имеет шорткат для добавления задачи и комбинации скрыть/показать выполненное.

Ты ещё со мной?.. Так вот, скрывало криво. Я дебажил соотв. функцию, в процессе получил красивую картинку. Не долго думая, выплеснул шум в сеть.

Вероятно, увидев три строчки Haskell ты подумал, что что-то пропустил? :) Не переживай, ничего интересного тут нет.

Ну, разве что ссылка на заметку про функциональные тесты (и блог http://sdk.org.nz/ вообще).

PS: Рад слышать, Серж!

(Reply to this) (Parent)


(2 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…