<commit_before>package katas.kotlin.leetcode.string_to_integer

import kotlincommon.test.shouldEqual
import org.junit.Test

class StringToIntegerTests {
    @Test fun `0 to 100`() {
        (0 until 10).forEach { it.toString().toInteger() shouldEqual it }
        (10 until 100).forEach { it.toString().toInteger() shouldEqual it }
    }

    @Test fun `-100 to 0`() {
        (-100 until 0).forEach { it.toString().toInteger() shouldEqual it }
    }
}

private fun String.toInteger(): Int {
    var result = 0
    var isNegative = false
    chars().forEach { char ->
        if (char == '-'.toInt()) isNegative = true
        else result = result * 10 + (char - '0'.toInt())
    }
    if (isNegative) result = -result
    return result
}
<commit_msg>string to integer<commit_after>package katas.kotlin.leetcode.string_to_integer

import kotlincommon.test.shouldEqual
import org.junit.Test

class StringToIntegerTests {
    @Test fun `0 to 100`() {
        (0 until 10).forEach { it.toString().toInteger() shouldEqual it }
        (10 until 100).forEach { it.toString().toInteger() shouldEqual it }
    }

    @Test fun `-100 to 0`() {
        (-100 until 0).forEach { it.toString().toInteger() shouldEqual it }
    }

    @Test fun `invalid input`() {
        "-".toInteger() shouldEqual 0
    }
}

private fun String.toInteger(): Int {
    var result = 0
    var isNegative = false
    chars().forEach { char ->
        if (char == '-'.toInt()) isNegative = true
        else result = result * 10 + (char - '0'.toInt())
    }
    if (isNegative) result = -result
    return result
}

{'fraction_non_alphanumeric': 0.13690851735015772, 'fraction_numerical': 0.030914826498422712, 'mean_word_length': 2.6628175519630486, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1373933', 'n_tokens_mistral': 537, 'n_tokens_neox': 486, 'n_words': 139}