Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from unittest import TestCase
class SpaceSplitter(object):
# Example of Python-based string_types.
@classmethod
def create(cls, param):
return cls()
def split(self, text):
"""
Splits the input text with space.
The input text is typed as ``str``.
This method should return list of boundaries (pair of beginning
position and length), e.g., ``[ (0, 1), (3, 4) ]``.
"""
result = []
begin = 0
length = 0
for (pos, char) in enumerate(text):
if char == ' ':
if 0 < length:
result.append((begin, length))
length = 0
begin = pos + 1
else:
length += 1
if length != 0:
result.append((begin, length))
return result
class SpaceSplitterTest(TestCase):
def test_split(self):
ex = SpaceSplitter.create({})
sentence = b' hi jubatus !'
# pos: 0123456789ABCD
self.assertEqual([(1, 2), (5, 7), (13, 1)], ex.split(sentence))