package main

import "testing"

func TestSubstr(t *testing.T) {
	tests := []struct {
		s   string
		ans int
	}{
		// Normal cases
		{"abcabcbb", 3},
		{"abcabcbb", 3},

		//Edge cases
		{"", 0},
		{"aaaaaaa", 1},
		{"abbabbabbc", 2},

		//chinese support
		{"这里我测试", 5},
	}

	for _, tt := range tests {
		if actual := lengthOfNonRepeatingSubStr(tt.s); actual != tt.ans {
			t.Errorf("got %d for input  %s : expected %d ", actual, tt.s, tt.ans)
		}
	}

}

func BenchmarkDubstr(b *testing.B) {
	s := "以html方式查询代码覆盖率报告文件码覆盖率报"
	ans := 18

	for i := 0; i < 13; i++ {
		s = s + s
	}

	b.Logf("len(s) = %d ", len(s))
	//重置时间
	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		actual := lengthOfNonRepeatingSubStr(s)
		if actual != ans {
			b.Errorf("got %d for input   : expected %d ", actual, ans)
		}
	}

}
