Add tests

Signed-off-by: Akira Hayakawa <ruby.wktk@gmail.com>
big refactoring

Signed-off-by: Akira Hayakawa <ruby.wktk@gmail.com>