t *testing.T) {
	expected := "hello world"

	r := bytes.NewReader([]byte(expected))

	got := leitor(r)
	if got!= expected {
		t.Errorf("leitor() = %v, want %v", got, expected)
	}
}

func Test_leEFecha(t *testing.T) {
	expected := "hello world"

	r := ioutil.NopCloser(bytes.NewReader([]byte(expected)))

	got := leEFecha(r)
	if got!= expected {
		t.Errorf("leEFecha() = %v, want %v", got, expected)
	}
}

func Test_responde(t *testing.T) {
	w := httptest.NewRecorder()
	expected := "{\"message\":\"algo muito importante\"}\n"

	responde(w)
	b := w.Body.Bytes()

	if string(b)!= expected {
		t.Errorf("responde(): expected %q, but got %q", expected, string(b))
	}

	if w.Header().Get("Content-Type")!= "application/json" {
		t.Errorf("responde(): expected Content-Type application/json, but got %q", w.Header().Get("Content-Type"))
	}
}

func Test_clienteHttp(t *testing.T) {
	serverOk := httptest.NewServer(
		http.HandlerFunc(
			func(w http.ResponseWriter, r *http.Request) {
				fmt.Fprintln(w, "ok")
			}))
	defer serverOk.Close()

	serverErr := httptest.NewServer(
		http.HandlerFunc(
			func(w http.ResponseWriter, r *http.Request) {
				http.Error(w, "error", http.StatusInternalServerError)
				fmt.Fprintln(w, "error")
			}))
	defer serverErr.Close()

	type args struct {
		token  string
		method string
		url    string
		body   io.Reader
	}
	tests := []struct {
		name       string
		args       args
		wantStatus int
		wantErr    bool
	}{
		{
			name:       "StatusOK",
			wantErr:    false,
			wantStatus: http.StatusOK,
			args: args{
				token:  "test",
				method: http.MethodGet,
				url:    serverOk.URL,
			},
		},
		{
			name:       "StatusInternalServerError",
			wantErr:    false,
			wantStatus: http.StatusInternalServerError,
			args: args{
				token:  "test",
				method: http.MethodGet,
				url:    serverErr.URL,
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			gotResp, err := clienteHttp(tt.args.token, tt.args.method, tt.args.url, tt.args.body)
			if (err!= nil)!= tt.wantErr {
				t.Errorf("clienteHttp() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if gotResp.StatusCode!= tt.wantStatus {
				t.Errorf("clienteHttp() = %v, want %v", gotResp.StatusCode, tt.wantStatus)
			}
		})
	}
}

/*
Testando a função closer() usando interfaces
*/

type closerSuccess struct {
}

func (c closerSuccess) Close() (err error) {
	return
}

type closerError struct {
}

func (c closerError) Close() (err error) {
	err = errors.New("closer error")
	return
}

func Test_closer(t *testing.T) {

	getStdout := func(obj io.Closer) (out []byte, err error) {
		rescueStdout := os.Stdout
		defer func() { os.Stdout = rescueStdout }()
		r, w, err := os.Pipe()
		if err!= nil {
			return nil, err
		}
		os.Stdout = w

		closer(obj)

		err = w.Close()
		if err!= nil {
			return
		}
		out, err = ioutil.ReadAll(r)
		return
	}

	cs := closerSuccess{}
	ce := closerError{}

	type args struct {
		body io.Closer
	}
	type expected struct {
		err bool
	}
	tests := []struct {
		name string
		args args
		want expected
	}{
		{
			name: "success",
			args: args{
				body: cs,
			},
			want: expected{
				err: false,
			},
		},
		{
			name: "error",
			args: args{
				body: ce,
			},
			want: expected{
				err: true,
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			out, err := getStdout(tt.args.body)
			if err!= nil {
				t.Error(err)
				return
			}

			if (len(out) > 0)!= tt.want.err {
				fmt.Printf("out: %q\n", string(out))
				t.Errorf("closer() unexpected log %q", string(out))
			}
		})
	}
}
.
Back to entriesComment on this entry
Stars
: 0
mwjyates
on 04 May 2008 at 14:01
Given his performance on HIGNFY I'm Backing Brian Blessed for the next london Mayor. (why not? worked for boris)
PS How long have you been a comedian/entertainer
PS How long have you been a comedian/entertainer
david
on 05 May 2008 at.
0star(s) awarded
same name different person... guess pr the comdedian earns more than me... he has the expensive dotcom, i have the dead cheap dotinfo....
0star(s) awarded
dave you are right.... think i will make a list of all the things we have been calling for for ages... border police..to name just another. also worth remembering that wheelies and war on supermarket shopping bags are all gordon's crazy notions too!
mwjyates
on 06 May 2008 at 10:21
Paul, Chorlton & the Wheelies pre dates G Brown by some years I think it was a Cosgrave Hall (of Dangermouse fame ) production.
Kids Tv-So much more interesting than politics
Kids Tv-So much more interesting than politics
0star(s) awarded
Aint that the truth... hang on... surely not much to choose between kids tv and local politics.... some great costumes... some degree of thought goes into doing it to please the masses... nobody takes it too seriuosly... same stuff just a matter of age.Optimization of RF excitation to maximize signal and T2 contrast of tissues with rapid transverse relaxation

Ultrashort echo time MRI requires specialized pulse sequences to overcome the short T2 of the MR signal encountered in tissues such as ligaments, tendon, or cortical bone. Theoretical work is presented, supported by simulations and experimental data on optimizing the radiofrequency excitation to maximize signal‐to‐noise ratio and contrast‐to‐noise ratio. The theoretical calculations and simulations are based on the classic Bloch equations and lead to a closed form expression for the optimal radiofrequency pulse parameters to maximize the MR signal in the presence of rapid T2 decay. In the steady state, the spoiled gradient recalled echo signal amplitude in response to the radiofrequency excitation pulses is not maximized by the classic Ernst angle but by a more general criterion we call “generalized Ernst angle.” Finally, it is shown that T2 contrast is maximized by flipping the magnetization at the Ernst angle with a radiofrequency pulse duration proportional to the targeted T2. Experimental studies on short T2 phantoms confirm these optimization criteria for both signal‐to‐noise ratio and contrast‐to‐noise ratio. Magn Reson Med, 2010. © 2010 Wiley‐Liss, Inc.You will be working with Soraya, Pilar, Mery, and our other interns in our central Salamanca office, two minutes from the Plaza Mayor.
New Year's Honour List recognises hard work from workers at the Office of National Statistics in Titchfield
THIS YEAR’S New Year Honour’s List has seen several workers from the Office of National Statistics in Titchfield receive plaudits for their efforts during the Covid-19