go-hep.org/x/hep@v0.38.1/fwk/job/stmt_test.go (about)

     1  // Copyright ©2017 The go-hep Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package job
     6  
     7  import (
     8  	"reflect"
     9  	"testing"
    10  
    11  	"go-hep.org/x/hep/fwk"
    12  	_ "go-hep.org/x/hep/fwk/internal/fwktest"
    13  )
    14  
    15  func TestStmt(t *testing.T) {
    16  
    17  	appcfg := C{
    18  		Name: "app",
    19  		Type: "go-hep.org/x/hep/fwk.appmgr",
    20  		Props: P{
    21  			"EvtMax": int64(10),
    22  			"NProcs": 42,
    23  		},
    24  	}
    25  
    26  	cfg0 := C{
    27  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
    28  		Name: "t0",
    29  		Props: P{
    30  			"Ints1": "t0-ints1",
    31  			"Ints2": "t0-ints2",
    32  		},
    33  	}
    34  
    35  	cfg1 := C{
    36  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
    37  		Name: "t1",
    38  		Props: P{
    39  			"Ints1": "t1-ints1",
    40  			"Ints2": "t1-ints2",
    41  		},
    42  	}
    43  
    44  	job := NewJob(
    45  		fwk.NewApp(),
    46  		appcfg.Props,
    47  	)
    48  
    49  	if job == nil {
    50  		t.Fatalf("got nil job.Job")
    51  	}
    52  
    53  	job.Create(cfg0)
    54  	job.Create(cfg1)
    55  
    56  	exp := []Stmt{
    57  		{
    58  			Type: StmtNewApp,
    59  			Data: appcfg,
    60  		},
    61  		{
    62  			Type: StmtCreate,
    63  			Data: cfg0,
    64  		},
    65  		{
    66  			Type: StmtCreate,
    67  			Data: cfg1,
    68  		},
    69  	}
    70  
    71  	stmts := job.Stmts()
    72  
    73  	if !reflect.DeepEqual(exp, stmts) {
    74  		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
    75  	}
    76  }
    77  
    78  func TestStmtWithProps(t *testing.T) {
    79  
    80  	appcfg := C{
    81  		Name: "app",
    82  		Type: "go-hep.org/x/hep/fwk.appmgr",
    83  		Props: P{
    84  			"EvtMax": int64(10),
    85  			"NProcs": 42,
    86  		},
    87  	}
    88  
    89  	cfg0 := C{
    90  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
    91  		Name: "t0",
    92  		Props: P{
    93  			"Ints1": "t0-ints1",
    94  			"Ints2": "t0-ints2",
    95  		},
    96  	}
    97  
    98  	cfg1 := C{
    99  		Type: "go-hep.org/x/hep/fwk/internal/fwktest.task1",
   100  		Name: "t1",
   101  		Props: P{
   102  			"Ints1": "t1-ints1",
   103  			"Ints2": "t1-ints2",
   104  		},
   105  	}
   106  
   107  	job := NewJob(
   108  		fwk.NewApp(),
   109  		appcfg.Props,
   110  	)
   111  
   112  	if job == nil {
   113  		t.Fatalf("got nil job.Job")
   114  	}
   115  
   116  	comp0 := job.Create(cfg0)
   117  	prop01 := P{
   118  		"Ints1": "t0-ints1-modified",
   119  	}
   120  	prop02 := P{
   121  		"Ints2": "t0-ints2-modified",
   122  	}
   123  
   124  	job.SetProp(comp0, "Ints1", prop01["Ints1"])
   125  	job.SetProp(comp0, "Ints2", prop02["Ints2"])
   126  
   127  	comp1 := job.Create(cfg1)
   128  
   129  	prop11 := P{
   130  		"Ints1": "t1-ints1-modified",
   131  	}
   132  	prop12 := P{
   133  		"Ints2": "t1-ints2-modified",
   134  	}
   135  
   136  	job.SetProp(comp1, "Ints1", prop11["Ints1"])
   137  	job.SetProp(comp1, "Ints2", prop12["Ints2"])
   138  
   139  	exp := []Stmt{
   140  		{
   141  			Type: StmtNewApp,
   142  			Data: appcfg,
   143  		},
   144  		{
   145  			Type: StmtCreate,
   146  			Data: cfg0,
   147  		},
   148  		{
   149  			Type: StmtSetProp,
   150  			Data: C{
   151  				Type:  comp0.Type(),
   152  				Name:  comp0.Name(),
   153  				Props: prop01,
   154  			},
   155  		},
   156  		{
   157  			Type: StmtSetProp,
   158  			Data: C{
   159  				Type:  comp0.Type(),
   160  				Name:  comp0.Name(),
   161  				Props: prop02,
   162  			},
   163  		},
   164  		{
   165  			Type: StmtCreate,
   166  			Data: cfg1,
   167  		},
   168  		{
   169  			Type: StmtSetProp,
   170  			Data: C{
   171  				Type:  comp1.Type(),
   172  				Name:  comp1.Name(),
   173  				Props: prop11,
   174  			},
   175  		},
   176  		{
   177  			Type: StmtSetProp,
   178  			Data: C{
   179  				Type:  comp1.Type(),
   180  				Name:  comp1.Name(),
   181  				Props: prop12,
   182  			},
   183  		},
   184  	}
   185  
   186  	stmts := job.Stmts()
   187  
   188  	if !reflect.DeepEqual(exp, stmts) {
   189  		t.Fatalf("unexpected statments:\nexp=%#v\ngot=%#v\n", exp, stmts)
   190  	}
   191  }