Skip to content
Snippets Groups Projects
Commit ec5d93f5 authored by LaurenceLiZhixin's avatar LaurenceLiZhixin
Browse files

fix: add test

parent e27b881e
No related branches found
No related tags found
No related merge requests found
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package match_judger
import (
"github.com/apache/dubbo-go/config"
"github.com/stretchr/testify/assert"
"testing"
)
func TestBoolMatchJudger(t *testing.T) {
assert.True(t, newBoolMatchJudger(&config.BoolMatch{
Exact: true,
}).Judge(true))
assert.True(t, newBoolMatchJudger(&config.BoolMatch{
Exact: false,
}).Judge(false))
assert.False(t, newBoolMatchJudger(&config.BoolMatch{
Exact: true,
}).Judge(false))
assert.False(t, newBoolMatchJudger(&config.BoolMatch{
Exact: false,
}).Judge(true))
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package match_judger
import (
"github.com/apache/dubbo-go/config"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDoubleMatchJudger(t *testing.T) {
assert.True(t, newDoubleMatchJudger(&config.DoubleMatch{
Exact: 3.14159,
}).Judge(3.14159))
assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{
Exact: 3.14159,
}).Judge(3.14155927))
assert.True(t, newDoubleMatchJudger(&config.DoubleMatch{
Range: &config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
},
}).Judge(1.3))
assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{
Range: &config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
},
}).Judge(1.9))
assert.False(t, newDoubleMatchJudger(&config.DoubleMatch{
Range: &config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
},
}).Judge(0.9))
}
package match_judger
import (
"github.com/apache/dubbo-go/config"
"github.com/stretchr/testify/assert"
"testing"
)
func TestDoubleRangeMatchJudger(t *testing.T) {
assert.True(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
}).Judge(1.3))
assert.False(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
}).Judge(1.9))
assert.False(t, newDoubleRangeMatchJudger(&config.DoubleRangeMatch{
Start: 1.0,
End: 1.5,
}).Judge(0.9))
}
package match_judger
import (
"github.com/apache/dubbo-go/config"
"github.com/stretchr/testify/assert"
"testing"
)
func TestListDoubleMatchJudger_Judge(t *testing.T) {
assert.True(t, newListDoubleMatchJudger(&config.ListDoubleMatch{
Oneof: []*config.DoubleMatch{
{
Exact: 3.14,
},
{
Range: &config.DoubleRangeMatch{
Start: 1.5,
End: 1.9,
},
},
{
Exact: 1.3,
},
},
}).Judge(1.3))
assert.False(t, newListDoubleMatchJudger(&config.ListDoubleMatch{
Oneof: []*config.DoubleMatch{
{
Exact: 3.14,
},
{
Range: &config.DoubleRangeMatch{
Start: 1.5,
End: 1.9,
},
},
{
Exact: 1.2,
},
},
}).Judge(1.3))
assert.True(t, newListDoubleMatchJudger(&config.ListDoubleMatch{
Oneof: []*config.DoubleMatch{
{
Exact: 3.14,
},
{
Range: &config.DoubleRangeMatch{
Start: 1.2,
End: 1.9,
},
},
{
Exact: 1.4,
},
},
}).Judge(1.3))
assert.False(t, newListDoubleMatchJudger(&config.ListDoubleMatch{
Oneof: []*config.DoubleMatch{
{
Exact: 3.14,
},
{
Range: &config.DoubleRangeMatch{
Start: 1.5,
End: 1.9,
},
},
{
Exact: 1.0,
},
},
}).Judge(1.3))
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment