github.com/nibnait/go-learn@v0.0.0-20220227013611-dfa47ea6d2da/src/test/chapter/ch1/06_condition_test.go (about)

     1  package ch1
     2  
     3  import "testing"
     4  
     5  func TestIfMultiSec(t *testing.T) {
     6  	if a := 1 == 1; a {
     7  		t.Log("1 == 1")
     8  	}
     9  
    10  	//if v,err := somFun(); err==nil {
    11  	//	t.Log("没有错误")
    12  	//} else {
    13  	//	t.Log("有错误")
    14  	//}
    15  }
    16  
    17  //func somFun()  {
    18  //	return 1, nil;
    19  //}
    20  
    21  func TestSwitchMultiCase(t *testing.T) {
    22  	for i := 0; i < 5; i++ {
    23  		switch i {
    24  		case 0, 2:
    25  			t.Log("Even")
    26  		case 1, 3:
    27  			t.Log("Odd")
    28  		default:
    29  			t.Log("it is not 0-3")
    30  		}
    31  	}
    32  }
    33  
    34  func TestSwitchCaseCondition(t *testing.T) {
    35  	for i := 0; i < 5; i++ {
    36  		switch {
    37  		case i%2 == 0:
    38  			t.Log("Even")
    39  		case i%2 == 1:
    40  			t.Log("Odd")
    41  		default:
    42  			t.Log("it is not 0-3")
    43  		}
    44  	}
    45  }