Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
NISP - Wheel Movements 0.1
#tclsh 8.6 #============================== UTOPE MOCK FUNCTIONS ========================================================================================== namespace eval tm { array set pars { NIST0129 72 # NIST0129 NISP_OMAGW_Pos_from_Home ICU ASW - GWA Position (degrees from home sensor) NIST0257 -72 # NIST0257 NISP_OMAFW_Pos_from_Home ICU ASW - FWA Position (degrees from home sensor) } } proc fetch {tm_name} {return $::tm::pars($tm_name)} proc getrawvalue {value} {return $value} #============================== L2* MOCK FUNCTIONS ========================================================================================== namespace eval ut { set nerrors 0 } namespace eval L2UTIL { proc ::L2UTIL::print {message {severity INFO}} {if {[string match "Current position is*" $message]} {} else {puts $message}} proc ::L2UTIL::generateError {errorDescription} {incr ut::nerrors; puts "$errorDescription"} } namespace eval L2TSEQ { proc ::L2TSEQ::begin {name arguments {precision MILLISECOND}} {} proc ::L2TSEQ::end {{mode AUTOMATIC}} {} proc ::L2TSEQ::step {title body} {puts "::L2TSEQ::step ------ $title ------"; eval $body; puts "::L2TSEQ::step ------ end ------";} } #============================== PLM FUNCTIONS ========================================================================================== namespace eval L3nisp_plm { proc ::L3nisp_plm::verify_filter_name { filter_name } { if {[lsearch -exact {OPEN CLOSE FILTER_H FILTER_Y FILTER_J} $filter_name] == -1} { set ::L3nisp_plm::filter_name $filter_name ::L2TSEQ::step "Error detected" { ::L2UTIL::generateError "Filter name '$::L3nisp_plm::filter_name' is not valid, allowed values {OPEN CLOSE FILTER_H FILTER_Y FILTER_J}" } } } proc ::L3nisp_plm::verify_grism_name { grism_name } { if {[lsearch -exact {RGS000 RGS180 OPEN BGS000 RGS270} $grism_name] == -1} { ### BUG FIXED IN THE NEXT LINE ### set ::L3nisp_plm::filter_name $filter_name set ::L3nisp_plm::filter_name $grism_name ::L2TSEQ::step "Error detected" { ::L2UTIL::generateError "Grism name '$::L3nisp_plm::filter_name' is not valid, allowed values {RGS000 RGS180 OPEN BGS000 RGS270}" } } } proc ::L3nisp_plm::find_current_wheel_position { wheel_id } { switch -exact -- $wheel_id { "GWA" { set tm_name NIST0129 } "FWA" { set tm_name NIST0257 } } set value [getrawvalue [fetch $tm_name]] if {![string is integer -strict $value] } { set ::L3nisp_plm::value $value ::L2TSEQ::step "Error detected" { ::L2UTIL::generateError "$wheel_id position read is not integer '$value' are TMs on?" } } set deg_to_int [expr $value % 5] switch -exact -- $wheel_id { "GWA" { switch -exact -- $deg_to_int { 0 { return "RGS000" } 1 { return "BGS000" } 2 { return "RGS180" } 3 { return "RGS270" } 4 { return "OPEN" } } } "FWA" { switch -exact -- $deg_to_int { 0 { return "CLOSE" } 1 { return "FILTER_J" } 2 { return "FILTER_Y" } 3 { return "FILTER_H" } 4 { return "OPEN" } } } } } proc ::L3nisp_plm::get_deg_based_on_current_filter_position { filter_name } { ::L3nisp_plm::verify_filter_name $filter_name set current_position [::L3nisp_plm::find_current_wheel_position "FWA"] ::L2UTIL::print "Current position is $current_position" INFO switch -exact -- $current_position { CLOSE { switch -exact -- $filter_name { default - CLOSE { return "0" } FILTER_Y { return "+72" } OPEN { return "+144" } FILTER_J { return "-144" } FILTER_H { return "-72" } } } FILTER_Y { switch -exact -- $filter_name { CLOSE { return "-72" } default - FILTER_Y { return "0" } OPEN { return "+72" } FILTER_J { return "+144" } FILTER_H { return "-144" } } } OPEN { switch -exact -- $filter_name { CLOSE { return "-144" } FILTER_Y { return "-72" } default - OPEN { return "0" } FILTER_J { return "+72" } FILTER_H { return "+144" } } } FILTER_J { switch -exact -- $filter_name { CLOSE { return "+144" } FILTER_Y { return "-144" } OPEN { return "-72" } default - FILTER_J { return "0 "} FILTER_H { return "+72" } } } FILTER_H { switch -exact -- $filter_name { CLOSE { return "+72" } FILTER_Y { return "+144" } OPEN { return "-144" } FILTER_J { return "-72" } default - FILTER_H { return "0" } } } default { return "0" } } } proc ::L3nisp_plm::get_deg_based_on_current_grism_position { grism_name } { ::L3nisp_plm::verify_grism_name $grism_name set current_position [::L3nisp_plm::find_current_wheel_position "GWA"] ::L2UTIL::print "Current position is $current_position" INFO switch -exact -- $current_position { RGS000 { switch -exact -- $grism_name { default - RGS000 { return "0" } RGS180 { return "+72" } OPEN { return "+144" } BGS000 { return "-144" } RGS270 { return "-72" } } } RGS180 { switch -exact -- $grism_name { RGS000 { return "-72" } default - RGS180 { return "0" } OPEN { return "+72" } BGS000 { return "+144" } RGS270 { return "-144" } } } OPEN { switch -exact -- $grism_name { RGS000 { return "-144" } RGS180 { return "-72" } default - OPEN { return "0" } BGS000 { return "+72" } RGS270 { return "+144" } } } BGS000 { switch -exact -- $grism_name { RGS000 { return "+144" } RGS180 { return "-144" } OPEN { return "-72" } default - BGS000 { return "0" } RGS270 { return "+72" } } } RGS270 { switch -exact -- $grism_name { RGS000 { return "+72" } RGS180 { return "+144" } OPEN { return "-144" } BGS000 { return "-72" } default - RGS270 { return "0" } } } default { return "0" } } } } #============================== NISP FUNCTION ========================================================================================== namespace eval L3nisp_fm_hlib { } #============================== UNIT TEST ========================================================================================== namespace eval ut { set ::ut::failed 0 set ::ut::passed 0 proc ::ut::test_verify_name {wheel_id name nerrors} { set ::ut::nerrors 0 if {$wheel_id == "FWA"} { ::L3nisp_plm::verify_filter_name $name } else { ::L3nisp_plm::verify_grism_name $name } set m [format "check name: %s %-9s errors %d " $wheel_id $name $ut::nerrors] if {$ut::nerrors == $nerrors} { ::L2UTIL::print [format "%30s %s" $m "PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [format "%30s %s" $m "**** FAILED ***** "] ERROR incr ::ut::failed } } proc ::ut::test_current_wheel_position {tm_name tm_value wheel_id expected_result} { set ::ut::nerrors 0 set ::tm::pars($tm_name) $tm_value set r [::L3nisp_plm::find_current_wheel_position $wheel_id] set m [format "%s %3i %3s %-8s = %-8s" $tm_name $tm_value $wheel_id $r $expected_result] if {$r == $expected_result} { ::L2UTIL::print [format "%30s %s" $m "PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [format "%30s %s" $m "**** FAILED ***** "] ERROR incr ::ut::failed } } proc ::ut::get_deg_based_on_current_grism_position {tm_name tm_value filter_name expected_result} { set ::ut::nerrors 0 set ::tm::pars($tm_name) $tm_value set current_name [::L3nisp_plm::find_current_wheel_position "GWA"] set r [::L3nisp_plm::get_deg_based_on_current_grism_position $filter_name] set m [format "%s %3i %-8s -> %-8s : %4i = %4i " $tm_name $tm_value $current_name $filter_name $r $expected_result] if {$r == $expected_result} { ::L2UTIL::print [format "%30s %s" $m "PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [format "%30s %s" $m "**** FAILED ***** "] ERROR incr ::ut::failed } } proc ::ut::get_deg_based_on_current_filter_position {tm_name tm_value filter_name expected_result} { set ::ut::nerrors 0 set ::tm::pars($tm_name) $tm_value set current_name [::L3nisp_plm::find_current_wheel_position "FWA"] set r [::L3nisp_plm::get_deg_based_on_current_filter_position $filter_name] set m [format "%s %3i %-8s -> %-8s : %4i = %4i " $tm_name $tm_value $current_name $filter_name $r $expected_result] if {$r == $expected_result} { ::L2UTIL::print [format "%30s %s" $m "PASSED"] OK incr ::ut::passed } else { ::L2UTIL::print [format "%30s %s" $m "**** FAILED ***** "] ERROR incr ::ut::failed } } # ----- ::L2TSEQ::begin $argv0 [concat $argv {-activity WE_Tests -conductor NISP_EGSE_Team }] ;# -mode SIMULATED namespace import ::* namespace import ::L3nisp_fm_hlib::* namespace import ::L3nisp_plm::* ::L2UTIL::print "\n***** RUN TEST 1 (::L3nisp_plm::verify_filter_name) *************************\n" OK ::ut::test_verify_name "FWA" OPEN 0 ::ut::test_verify_name "FWA" CLOSE 0 ::ut::test_verify_name "FWA" FILTER_H 0 ::ut::test_verify_name "FWA" FILTER_Y 0 ::ut::test_verify_name "FWA" FILTER_J 0 ::L2UTIL::print "\n***** RUN TEST 2 (::L3nisp_plm::verify_filter_name, FAKE) *************************\n" OK ::ut::test_verify_name "FWA" DUM 1 ::L2UTIL::print "\n***** RUN TEST 3 (::L3nisp_plm::verify_grism_name) *************************\n" OK ::ut::test_verify_name "GWA" RGS000 0 ::ut::test_verify_name "GWA" RGS180 0 ::ut::test_verify_name "GWA" OPEN 0 ::ut::test_verify_name "GWA" BGS000 0 ::ut::test_verify_name "GWA" RGS270 0 ::L2UTIL::print "\n***** RUN TEST 4 (::L3nisp_plm::verify_grism_name, FAKE) *************************\n" OK ::ut::test_verify_name "GWA" DUM 1 ::L2UTIL::print "\n***** RUN TEST 5 (::L3nisp_plm::find_current_wheel_position) *************************\n" OK ::L2UTIL::print "tm_name val wheel output expected result" OK ::L2UTIL::print "-------------------------------------------------------------" OK ::ut::test_current_wheel_position NIST0257 0 "FWA" "CLOSE" ::ut::test_current_wheel_position NIST0257 72 "FWA" "FILTER_Y" ::ut::test_current_wheel_position NIST0257 144 "FWA" "OPEN" ::ut::test_current_wheel_position NIST0257 216 "FWA" "FILTER_J" ::ut::test_current_wheel_position NIST0257 288 "FWA" "FILTER_H" puts "" ::ut::test_current_wheel_position NIST0129 0 "GWA" "RGS000" ::ut::test_current_wheel_position NIST0129 72 "GWA" "RGS180" ::ut::test_current_wheel_position NIST0129 144 "GWA" "OPEN" ::ut::test_current_wheel_position NIST0129 216 "GWA" "BGS000" ::ut::test_current_wheel_position NIST0129 288 "GWA" "RGS270" ::L2UTIL::print "\n***** RUN TEST 6 (::L3nisp_plm::find_current_wheel_position, FAKE) *************************\n" OK ::L2UTIL::print "tm_name val wheel output expected result" OK ::L2UTIL::print "-------------------------------------------------------------" OK ::ut::test_current_wheel_position NIST0257 1 "FWA" "" ::ut::test_current_wheel_position NIST0257 2 "FWA" "" ::ut::test_current_wheel_position NIST0257 3 "FWA" "" ::ut::test_current_wheel_position NIST0257 4 "FWA" "" ::ut::test_current_wheel_position NIST0257 5 "FWA" "" puts "" ::ut::test_current_wheel_position NIST0257 45 "FWA" "" ::ut::test_current_wheel_position NIST0257 90 "FWA" "" ::ut::test_current_wheel_position NIST0257 135 "FWA" "" ::ut::test_current_wheel_position NIST0257 225 "FWA" "" ::ut::test_current_wheel_position NIST0257 270 "FWA" "" ::ut::test_current_wheel_position NIST0257 315 "FWA" "" puts "" ::ut::test_current_wheel_position NIST0129 1 "GWA" "" ::ut::test_current_wheel_position NIST0129 2 "GWA" "" ::ut::test_current_wheel_position NIST0129 3 "GWA" "" ::ut::test_current_wheel_position NIST0129 4 "GWA" "" ::ut::test_current_wheel_position NIST0129 5 "GWA" "" puts "" ::ut::test_current_wheel_position NIST0129 45 "GWA" "" ::ut::test_current_wheel_position NIST0129 90 "GWA" "" ::ut::test_current_wheel_position NIST0129 135 "GWA" "" ::ut::test_current_wheel_position NIST0129 225 "GWA" "" ::ut::test_current_wheel_position NIST0129 270 "GWA" "" ::ut::test_current_wheel_position NIST0129 315 "GWA" "" ::L2UTIL::print "\n***** RUN TEST 7 (::L3nisp_plm::get_deg_based_on_current_grism_position) *************************\n" OK ::L2UTIL::print "tm_name val from to output expected result" OK ::L2UTIL::print "-------------------------------------------------------------" OK ::ut::get_deg_based_on_current_grism_position NIST0129 0 "RGS000" 0 ::ut::get_deg_based_on_current_grism_position NIST0129 0 "RGS180" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 0 "OPEN" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 0 "BGS000" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 0 "RGS270" 12 puts "" ::ut::get_deg_based_on_current_grism_position NIST0129 72 "RGS000" 0 ::ut::get_deg_based_on_current_grism_position NIST0129 72 "RGS180" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 72 "OPEN" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 72 "BGS000" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 72 "RGS270" 12 puts "" ::ut::get_deg_based_on_current_grism_position NIST0129 144 "RGS000" 0 ::ut::get_deg_based_on_current_grism_position NIST0129 144 "RGS180" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 144 "OPEN" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 144 "BGS000" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 144 "RGS270" 12 puts "" ::ut::get_deg_based_on_current_grism_position NIST0129 216 "RGS000" 0 ::ut::get_deg_based_on_current_grism_position NIST0129 216 "RGS180" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 216 "OPEN" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 216 "BGS000" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 216 "RGS270" 12 puts "" ::ut::get_deg_based_on_current_grism_position NIST0129 288 "RGS000" 0 ::ut::get_deg_based_on_current_grism_position NIST0129 288 "RGS180" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 288 "OPEN" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 288 "BGS000" 12 ::ut::get_deg_based_on_current_grism_position NIST0129 288 "RGS270" 12 ::L2UTIL::print "\n***** RUN TEST 8 (::L3nisp_plm::get_deg_based_on_current_filter_position) *************************\n" OK ::L2UTIL::print "tm_name val from to output expected result" OK ::L2UTIL::print "-------------------------------------------------------------" OK ::ut::get_deg_based_on_current_filter_position NIST0257 0 "CLOSE" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 0 "FILTER_Y" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 0 "OPEN" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 0 "FILTER_J" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 0 "FILTER_H" 12 puts "" ::ut::get_deg_based_on_current_filter_position NIST0257 72 "CLOSE" 0 ::ut::get_deg_based_on_current_filter_position NIST0257 72 "FILTER_Y" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 72 "OPEN" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 72 "FILTER_J" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 72 "FILTER_H" 12 puts "" ::ut::get_deg_based_on_current_filter_position NIST0257 144 "CLOSE" 0 ::ut::get_deg_based_on_current_filter_position NIST0257 144 "FILTER_Y" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 144 "OPEN" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 144 "FILTER_J" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 144 "FILTER_H" 12 puts "" ::ut::get_deg_based_on_current_filter_position NIST0257 216 "CLOSE" 0 ::ut::get_deg_based_on_current_filter_position NIST0257 216 "FILTER_Y" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 216 "OPEN" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 216 "FILTER_J" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 216 "FILTER_H" 12 puts "" ::ut::get_deg_based_on_current_filter_position NIST0257 288 "CLOSE" 0 ::ut::get_deg_based_on_current_filter_position NIST0257 288 "FILTER_Y" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 288 "OPEN" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 288 "FILTER_J" 12 ::ut::get_deg_based_on_current_filter_position NIST0257 288 "FILTER_H" 12 ::L2UTIL::print "\n***** RUN TEST 9 (::L3nisp_plm::get_deg_based_on_current_grism_position, FAKE) *************************\n" OK ::L2UTIL::print "tm_name val from to output expected result" OK ::L2UTIL::print "-------------------------------------------------------------" OK ::ut::get_deg_based_on_current_grism_position NIST0129 45 "RGS000" 0 ; ### ....IT PASSES BUT SHOULD BE AN ERROR! ::ut::get_deg_based_on_current_grism_position NIST0129 0 "DUM" 0 ; ### IT GENERATES AN UNMANAGED ERROR! if { $::ut::failed > 0 } { set msg_type ERROR } else { set msg_type OK } ::L2UTIL::print "\n\nRESULT: $::ut::passed passed, $::ut::failed FAILED\n" $msg_type ::L2TSEQ::end REQUEST }
run
|
edit
|
history
|
help
0
Santosh bin mul eo
NISP - Planning ID Unit Test
wewew
eerewr
Perfect neg float bin multiplier
test
Perfect fl bin mul
fl mul bin
Working for neg
q1q0