comparetotest.groovy

来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 38 行

GROOVY
38
字号
class CompareToTest extends GroovyTestCase {

    void testCompareTo() {

        def a = 12
        def b = 20
        def c = 30
        
        def result = a <=> b
        assert result < 0

        result = a <=> 12
        assert result == 0

        result = c <=> b
        assert result > 0
        
        assert (a <=> b) < 0
        assert a <=> 12 == 0
        assert (c <=> b) > 0
    }

    void testNullCompares() {
    
    	def a = 123
    	def b = null
    	
    	def result = a <=> b
    	assert result > 0
    	
    	result = b <=> a
    	assert result < 0
    	
    	result = b <=> null
    	assert result == 0
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?