コード例 #1
0
ファイル: matrix_test.go プロジェクト: rwl/goshawk
func testMatrixPositiveValues(t *testing.T, A positiveValuesMatrix) {
	A.Assign(0)
	A.SetQuick(A.Rows()/3, A.Columns()/3, 0.7)
	A.SetQuick(A.Rows()/2, A.Columns()/2, 0.1)
	var rowList []int
	var columnList []int
	var valueList []float64
	A.PositiveValues(&rowList, &columnList, &valueList)
	if len(rowList) != 2 {
		t.Errorf("expected:%d actual:%d", 2, len(rowList))
	}
	if len(columnList) != 2 {
		t.Errorf("expected:%d actual:%d", 2, len(columnList))
	}
	if !common.ContainsInt(rowsList, A.Rows()/3) {
		t.Errorf("missing:%d", A.Rows()/3)
	}
	if !common.ContainsInt(rowList, A.Rows()/2) {
		t.Errorf("missing:%d", A.Rows()/2)
	}
	if !common.ContainsInt(columnList, A.Columns()/3) {
		t.Errorf("missing:%d", A.Columns()/3)
	}
	if !common.ContainsInt(columnList, A.Columns()/2) {
		t.Errorf("missing:%d", A.Columns()/2)
	}
	if !common.ContainsFloat(valueList, 0.7, tol) {
		t.Errorf("missing:%g", 0.7)
	}
	if !common.ContainsFloat(valueList, 0.1, tol) {
		t.Errorf("missing:%g", 0.1)
	}
}
コード例 #2
0
ファイル: vector_test.go プロジェクト: rwl/goshawk
func testGetNegativeValues(t *testing.T, A negativeValuesVector) {
	A.Assign(0)
	A.SetQuick(A.Size()/3, -0.7)
	A.SetQuick(A.Size()/2, -0.1)
	var indexList []int
	var valueList []float64
	A.NegativeValues(&indexList, &valueList)
	if len(indexList) != 2 {
		t.Errorf("expected:%d actual:%d", 2, len(indexList))
	}
	if len(valueList) != 2 {
		t.Errorf("expected:%d actual:%d", 2, len(valueList))
	}
	if !common.ContainsInt(indexList, A.Size()/3) {
		t.Errorf("missing:%d", A.Size()/3)
	}
	if !common.ContainsInt(indexList, A.Size()/2) {
		t.Errorf("missing:%d", A.Size()/2)
	}
	if !common.ContainsFloat(valueList, -0.7, tol) {
		t.Errorf("missing:%g", -0.7)
	}
	if !common.ContainsFloat(valueList, -0.1, tol) {
		t.Errorf("missing:%g", -0.1)
	}
}