ethereumjs/ethereumjs-common-3-test

查看test能夠讓你更好滴了解其API文檔的使用

ethereumjs-common/tests/chains.js

const tape = require('tape')
const Common = require('../index.js')tape('[Common]: Initialization / Chain params', function (t) {t.test('Should initialize with chain provided', function (st) {//只使用chain來初始化一個Common對象let c = new Common('mainnet')//使用的是mainnet鏈st.equal(c.chainName(), 'mainnet', 'should initialize with chain name')//使用chainName API得到當前鏈名st.equal(c.chainId(), 1, 'should return correct chain Id') //得到chainIdst.equal(c.networkId(), 1, 'should return correct network Id') //得到networkIdst.equal(c.hardfork(), null, 'should set hardfork to null') //使用的硬分叉,因為沒有設置,所以是nullst.equal(c._isSupportedHardfork('constantinople'), true, 'should not restrict supported HFs') //是否支持constantinople硬分叉,這是默認支持的硬分叉類型中的一種,所以返回true
c = new Common(1) //也可以使用chain ID數字來表示mainnet鏈st.equal(c.chainName(), 'mainnet', 'should initialize with chain Id')st.end()})t.test('Should initialize with chain and hardfork provided', function (st) { //使用chain和hardfork兩個參數來初始化對象let c = new Common('mainnet', 'byzantium') //chain = mainnet ,hardfork = byzantiumst.equal(c.hardfork(), 'byzantium', 'should return correct hardfork name')st.end()})t.test('Should initialize with supportedHardforks provided', function (st) { //使用chain、hardfork和supportedHardforks三個參數來初始化對象let c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople']) //supportedHardforks = ['byzantium', 'constantinople'],設置只支持這兩個硬分叉類型st.equal(c._isSupportedHardfork('byzantium'), true, 'should return true for supported HF')st.equal(c._isSupportedHardfork('spuriousDragon'), false, 'should return false for unsupported HF')//因為supportedHardforks中沒有它,所以不支持
st.end()})t.test('Should handle initialization errors', function (st) {st.throws(function () { new Common('chainnotexisting') }, /not supported$/, 'should throw an exception on non-existing chain') // eslint-disable-line no-new ,不是支持的chain類型st.throws(function () { new Common('mainnet', 'hardforknotexisting') }, /not supported$/, 'should throw an exception on non-existing hardfork') // eslint-disable-line no-new ,不是支持的hardfork類型st.throws(function () { new Common('mainnet', 'spuriousDragon', ['byzantium', 'constantinople']) }, /supportedHardforks$/, 'should throw an exception on conflicting active/supported HF params') // eslint-disable-line no-new ,不是supportedHardforks中包含的hardfork類型
st.end()})t.test('Should provide correct access to chain parameters', function (st) {let c = new Common('mainnet')st.equal(c.genesis().hash, '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', 'should return correct genesis hash')//返回當前鏈的初始狀態中的hash值st.equal(c.hardforks()[3]['block'], 2463000, 'should return correct hardfork data')//返回當前鏈的硬分叉數組中第四個分叉的'block'值st.equal(c.bootstrapNodes()[0].port, 30303, 'should return a bootstrap node array')//返回當前鏈的所有bootstrap節點字典中第一個節點的端口port值
st.end()})t.test('Should be able to access data for all chains provided', function (st) {let c = new Common('mainnet')st.equal(c.genesis().hash, '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3', 'mainnet')c.setChain('ropsten') //重新將鏈設置為ropstenst.equal(c.genesis().hash, '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d', 'ropsten')c.setChain('rinkeby')st.equal(c.genesis().hash, '0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177', 'rinkeby')c.setChain('kovan')st.equal(c.genesis().hash, '0xa3c565fc15c7478862d50ccd6561e3c06b24cc509bf388941c25ea985ce32cb9', 'kovan')c.setChain('goerli')st.equal(c.genesis().hash, '0xfa57319d09fd8a32faaf18d338c8a925a5a7975285bf29ecd024e083cba8abb1', 'goerli')st.end()})t.test('Should provide correct access to private network chain parameters', function (st) {//如果你連接的chain不是上面那些定義好的chain,而是你私有的或定制的,初始化的方式是下面這樣的let chainParams = require('./testnet.json') //testnet.json中是具體的鏈描述信息let c = new Common(chainParams, 'byzantium')st.equal(c.chainName(), 'testnet', 'should initialize with chain name')st.equal(c.chainId(), 12345, 'should return correct chain Id')st.equal(c.networkId(), 12345, 'should return correct network Id')st.equal(c.genesis().hash, '0xaa00000000000000000000000000000000000000000000000000000000000000', 'should return correct genesis hash')st.equal(c.hardforks()[3]['block'], 3, 'should return correct hardfork data')st.equal(c.bootstrapNodes()[1].ip, '10.0.0.2', 'should return a bootstrap node array')st.end()})t.test('Should handle custom chain parameters with missing field', function (st) {let chainParams = require('./testnet.json')delete chainParams['hardforks'] //如果有任何內容的缺失,初始化時將報錯st.throws(function () { new Common(chainParams) }, /Missing required/, 'should throw an exception on missing parameter') // eslint-disable-line no-new
st.end()})
})

?

ethereumjs-common/tests/hardforks.js

const tape = require('tape')
const Common = require('../index.js')tape('[Common]: Hardfork logic', function (t) {t.test('Hardfork access', function (st) {let supportedHardforks = [ //設置支持的硬分支類型'chainstart','homestead','dao','tangerineWhistle','spuriousDragon','byzantium','constantinople']let cfor (let hardfork of supportedHardforks) {c = new Common('mainnet', hardfork)st.equal(c.hardfork(), hardfork, hardfork)}st.end()})t.test('hardforkBlock()', function (st) {let c = new Common('ropsten')st.equal(c.hardforkBlock('byzantium'), 1700000, 'should return the correct HF change block for byzantium (provided)') //得到byzantium分叉開始的區塊數
c = new Common('ropsten', 'byzantium')st.equal(c.hardforkBlock(), 1700000, 'should return the correct HF change block for byzantium (set)')st.end()})t.test('isHardforkBlock()', function (st) {let c = new Common('ropsten')st.equal(c.isHardforkBlock(1700000, 'byzantium'), true, 'should return true for HF change block for byzantium (provided)')st.equal(c.isHardforkBlock(1700001, 'byzantium'), false, 'should return false for another block for byzantium (provided)')c = new Common('ropsten', 'byzantium')st.equal(c.isHardforkBlock(1700000), true, 'should return true for HF change block for byzantium (set)')st.equal(c.isHardforkBlock(1700001), false, 'should return false for another block for byzantium (set)')st.end()})t.test('activeHardforks()', function (st) {let c = new Common('ropsten')st.equal(c.activeHardforks().length, 5, 'should return 5 active hardforks for Ropsten') //說明ropsten鏈中有5個活躍分叉類型st.equal(c.activeHardforks()[3]['name'], 'spuriousDragon', 'should return the correct HF data for Ropsten')st.equal(c.activeHardforks(9).length, 3, 'should return 3 active hardforks for Ropsten up to block 9')//即直到區塊9有的活躍分叉個數為3st.equal(c.activeHardforks(10).length, 4, 'should return 4 active hardforks for Ropsten up to block 10')c = new Common('ropsten', null, ['spuriousDragon', 'byzantium', 'constantinople'])//onlySupported: true說明只支持supportedHardforks里面的分叉,所以返回的結果就從5變成了2,只包含了2個活躍分叉類型st.equal(c.activeHardforks(null, { onlySupported: true }).length, 2, 'should return 2 active HFs when restricted to supported HFs')st.end()})t.test('activeHardfork()', function (st) {let c = new Common('ropsten')st.equal(c.activeHardfork(), 'byzantium', 'should return byzantium as latest active HF for Ropsten') //說明整條鏈最新的分叉為byzantiumst.equal(c.activeHardfork(10), 'spuriousDragon', 'should return spuriousDragon as latest active HF for Ropsten for block 10') //即到區塊10的最新分叉類型為spuriousDragon
c = new Common('ropsten', null, ['tangerineWhistle', 'spuriousDragon'])//返回'spuriousDragon',因為supportedHardforks里最新的類型為它st.equal(c.activeHardfork(null, { onlySupported: true }), 'spuriousDragon', 'should return spuriousDragon as latest active HF for Ropsten with limited supported hardforks')st.end()})t.test('hardforkIsActiveOnBlock() / activeOnBlock()', function (st) {let c = new Common('ropsten')st.equal(c.hardforkIsActiveOnBlock('byzantium', 1700000), true, 'Ropsten, byzantium (provided), 1700000 -> true')st.equal(c.hardforkIsActiveOnBlock('byzantium', 1700005), true, 'Ropsten, byzantium (provided), 1700005 -> true')st.equal(c.hardforkIsActiveOnBlock('byzantium', 1699999), false, 'Ropsten, byzantium (provided), 1699999 -> false')c = new Common('ropsten', 'byzantium')st.equal(c.hardforkIsActiveOnBlock(null, 1700000), true, 'Ropsten, byzantium (set), 1700000 -> true')st.equal(c.activeOnBlock(1700000), true, 'Ropsten, byzantium (set), 1700000 -> true (alias function)')st.equal(c.hardforkIsActiveOnBlock(null, 1700005), true, 'Ropsten, byzantium (set), 1700005 -> true')st.equal(c.hardforkIsActiveOnBlock(null, 1699999), false, 'Ropsten, byzantium (set), 1699999 -> false')st.end()})t.test('hardforkGteHardfork()', function (st) {let c = new Common('ropsten')st.equal(c.hardforkGteHardfork('constantinople', 'byzantium'), true, 'Ropsten, constantinople >= byzantium (provided) -> true')st.equal(c.hardforkGteHardfork('constantinople', 'byzantium', { onlyActive: true }), false, 'Ropsten, constantinople >= byzantium (provided), onlyActive -> fale')st.equal(c.hardforkGteHardfork('byzantium', 'byzantium'), true, 'Ropsten, byzantium >= byzantium (provided) -> true')st.equal(c.hardforkGteHardfork('spuriousDragon', 'byzantium'), false, 'Ropsten, spuriousDragon >= byzantium (provided) -> false')c = new Common('ropsten', 'byzantium')st.equal(c.hardforkGteHardfork(null, 'spuriousDragon'), true, 'Ropsten, byzantium (set) >= spuriousDragon -> true')st.equal(c.gteHardfork('spuriousDragon'), true, 'Ropsten, byzantium (set) >= spuriousDragon -> true (alias function)')st.equal(c.hardforkGteHardfork(null, 'spuriousDragon', { onlyActive: true }), true, 'Ropsten, byzantium (set) >= spuriousDragon, onlyActive -> true')st.equal(c.hardforkGteHardfork(null, 'byzantium'), true, 'Ropsten, byzantium (set) >= byzantium -> true')st.equal(c.hardforkGteHardfork(null, 'constantinople'), false, 'Ropsten, byzantium (set) >= constantinople -> false')st.end()})t.test('hardforkIsActiveOnChain()', function (st) {let c = new Common('ropsten')st.equal(c.hardforkIsActiveOnChain('byzantium'), true, 'should return true for byzantium (provided) on Ropsten')st.equal(c.hardforkIsActiveOnChain('dao'), false, 'should return false for dao (provided) on Ropsten')st.equal(c.hardforkIsActiveOnChain('constantinople'), false, 'should return false for constantinople (provided) on Ropsten')st.equal(c.hardforkIsActiveOnChain('notexistinghardfork'), false, 'should return false for a non-existing HF (provided) on Ropsten')//因為這里并沒有設置,但是使用了onlySupported: true,所以會報出"spuriousDragon"為不支持的分叉的錯誤st.doesNotThrow(function () { c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) }, /unsupported hardfork$/, 'should not throw with unsupported Hf (provided) and onlySupported set to false') // eslint-disable-line no-new
c = new Common('ropsten', 'byzantium')st.equal(c.hardforkIsActiveOnChain(), true, 'should return true for byzantium (set) on Ropsten')c = new Common('ropsten', null, ['byzantium', 'constantinople'])st.throws(function () { c.hardforkIsActiveOnChain('spuriousDragon', { onlySupported: true }) }, /not set as supported in supportedHardforks$/, 'should throw with unsupported Hf and onlySupported set to true') // eslint-disable-line no-new
st.end()})t.test('consensus()/finality()', function (st) {let c = new Common('mainnet')st.equal(c.consensus('byzantium'), 'pow', 'should return pow for byzantium consensus')//返回byzantium分叉共識為'pow'st.equal(c.consensus('constantinople'), 'pow', 'should return pow for constantinople consensus')st.equal(c.finality('byzantium'), null, 'should return null for byzantium finality')st.end()})
})

?

ethereumjs-common/tests/params.js

const tape = require('tape')
const Common = require('../index.js')tape('[Common]: Parameter access', function (t) {//這個測試就是獲取參數值t.test('Basic usage', function (st) {let c = new Common('mainnet')st.equal(c.param('gasPrices', 'ecAdd', 'byzantium'), 500, 'Should return correct value when HF directly provided')c.setHardfork('byzantium')st.equal(c.param('gasPrices', 'ecAdd'), 500, 'Should return correct value for HF set in class')st.end()})t.test('Error cases', function (st) {let c = new Common('mainnet')st.throws(function () { c.param('gasPrices', 'ecAdd') }, /neither a hardfork set nor provided by param$/, 'Should throw when no hardfork set or provided')st.throws(function () { c.param('gasPrizes', 'ecAdd', 'byzantium') }, /Topic gasPrizes not defined$/, 'Should throw when called with non-existing topic')st.throws(function () { c.param('gasPrices', 'notexistingvalue', 'byzantium') }, /value for notexistingvalue not found$/, 'Should throw when called with non-existing value')c.setHardfork('byzantium')st.equal(c.param('gasPrices', 'ecAdd'), 500, 'Should return correct value for HF set in class')c = new Common('mainnet', 'byzantium', ['byzantium', 'constantinople'])st.throws(function () { c.param('gasPrices', 'expByte', 'spuriousDragon') }, /supportedHardforks$/, 'Should throw when calling param() with an unsupported hardfork')st.throws(function () { c.paramByBlock('gasPrices', 'expByte', 0) }, /supportedHardforks$/, 'Should throw when calling paramByBlock() with an unsupported hardfork')st.end()})t.test('Parameter updates', function (st) {let c = new Common('mainnet')st.throws(function () { c.param('gasPrices', 'ecAdd', 'spuriousDragon') }, /value for ecAdd not found$/, 'Should throw for a value set on a later HF')st.equal(c.param('pow', 'minerReward', 'chainstart'), '5000000000000000000', 'Should return correct value for chain start')st.equal(c.param('pow', 'minerReward', 'byzantium'), '3000000000000000000', 'Should reflect HF update changes')st.equal(c.param('gasPrices', 'netSstoreNoopGas', 'constantinople'), 200, 'Should return updated sstore gas prices for constantinople')st.end()})t.test('Access by block number, paramByBlock()', function (st) {let c = new Common('mainnet', 'byzantium')st.equal(c.paramByBlock('pow', 'minerReward', 4370000), '3000000000000000000', 'Should correctly translate block numbers into HF states (updated value)')st.equal(c.paramByBlock('pow', 'minerReward', 4369999), '5000000000000000000', 'Should correctly translate block numbers into HF states (original value)')st.end()})
})

?

ethereumjs-common/tests/testnet.json

{"name": "testnet","chainId": 12345,"networkId": 12345,"comment": "Private test network","genesis": {"hash": "0xaa00000000000000000000000000000000000000000000000000000000000000","timestamp": null,"gasLimit": 1000000,"difficulty": 1,"nonce": "0xbb00000000000000","extraData": "0xcc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","stateRoot": "0xdd00000000000000000000000000000000000000000000000000000000000000"},"hardforks": [{"name": "chainstart","block": 0,"consensus": "poa","finality": null},{"name": "homestead","block": 1,"consensus": "poa","finality": null},{"name": "tangerineWhistle","block": 2,"consensus": "poa","finality": null},{"name": "spuriousDragon","block": 3,"consensus": "poa","finality": null},{"name": "byzantium","block": 4,"consensus": "poa","finality": null}],"bootstrapNodes": [{"ip": "10.0.0.1","port": 30303,"id": "11000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","location": "","comment": ""},{"ip": "10.0.0.2","port": 30303,"id": "22000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","location": "","comment": ""}]
}

?

轉載于:https://www.cnblogs.com/wanghui-garcia/p/10089565.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388943.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388943.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388943.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mysql修改_mysql修改表操作

一: 修改表信息1.修改表名alter table test_a rename to sys_app;2.修改表注釋alter table sys_application comment 系統信息表;二:修改字段信息1.修改字段類型和注釋alter table sys_application modify column app_name varchar(20) COMMENT 應用的名…

機器學習實踐四--正則化線性回歸 和 偏差vs方差

這次實踐的前半部分是,用水庫水位的變化,來預測大壩的出水量。 給數據集擬合一條直線,可能得到一個邏輯回歸擬合,但它并不能很好地擬合數據,這是高偏差(high bias)的情況,也稱為“欠…

深度學習 推理 訓練_使用關系推理的自我監督學習進行訓練而無需標記數據

深度學習 推理 訓練背景與挑戰📋 (Background and challenges 📋) In a modern deep learning algorithm, the dependence on manual annotation of unlabeled data is one of the major limitations. To train a good model, usually, we have to prepa…

Android strings.xml中定義字符串顯示空格

<string name"str">字 符 串</string> 其中 就表示空格。如果直接在里面鍵入空格&#xff0c;無論多少空格都只會顯示一個。 用的XML轉義字符記錄如下&#xff1a; 空格&#xff1a; <string name"out_bound_submit">出 庫</strin…

WCF開發入門的六個步驟

在這里我就用一個據于一個簡單的場景&#xff1a;服務端為客服端提供獲取客戶信息的一個接口讀取客戶信息&#xff0c;來完成WCF開發入門的六個步驟。 1. 定義WCF服務契約 A. 項目引用節點右鍵添加引用。 B. 在代碼文件里&#xff0c;添加以下命名空間的引…

LOJ116 有源匯有上下界最大流(上下界網絡流)

考慮有源匯上下界可行流&#xff1a;由匯向源連inf邊&#xff0c;那么變成無源匯圖&#xff0c;按上題做法跑出可行流。此時該inf邊的流量即為原圖中該可行流的流量。因為可以假裝把加上去的那些邊的流量放回原圖。 此時再從原來的源向原來的匯跑最大流。超源超匯相關的邊已經流…

CentOS 7 使用 ACL 設置文件權限

Linux 系統標準的 ugo/rwx 集合并不允許為不同的用戶配置不同的權限&#xff0c;所以 ACL 便被引入了進來&#xff0c;為的是為文件和目錄定義更加詳細的訪問權限&#xff0c;而不僅僅是這些特別指定的特定權限。 ACL 可以為每個用戶&#xff0c;每個組或不在文件所屬組中的用…

機器學習實踐五---支持向量機(SVM)

之前已經學到了很多監督學習算法&#xff0c; 今天的監督學習算法是支持向量機&#xff0c;與邏輯回歸和神經網絡算法相比&#xff0c;它在學習復雜的非線性方程時提供了一種更為清晰&#xff0c;更強大的方式。 Support Vector Machines SVM hypothesis Example Dataset 1…

作為微軟技術.net 3.5的三大核心技術之一的WCF雖然沒有WPF美麗的外觀

作為微軟技術.net 3.5的三大核心技術之一的WCF雖然沒有WPF美麗的外觀 但是它卻是我們開發分布式程序的利器 但是目前關于WCF方面的資料相當稀少 希望我的這一系列文章可以幫助大家盡快入門 下面先介紹一下我的開發環境吧 操作系統&#xff1a;windows vista business版本 編譯器…

服務器安裝mysql_阿里云服務器上安裝MySQL

關閉防火墻和selinuxCentOS7以下&#xff1a;service iptables stopsetenforce 0CentOS7.xsystemctl stop firewalldsystemctl disable firewalldsystemctl status firewalldvi /etc/selinux/config把SELINUXenforcing 改成 SELINUXdisabled一、安裝依賴庫yum -y install make …

在PyTorch中轉換數據

In continuation of my previous post ,we will keep on deep diving into basic fundamentals of PyTorch. In this post we will discuss about ways to transform data in PyTorch.延續我以前的 發布后 &#xff0c;我們將繼續深入研究PyTorch的基本原理。 在這篇文章中&a…

「網絡流24題」試題庫問題

傳送門&#xff1a;>Here< 題意&#xff1a;有K種類型的共N道試題用來出卷子&#xff0c;要求卷子須有M道試題。已知每道題屬于p種類型&#xff0c;每種類型的試題必須有且僅有k[i]道。現問出這套試卷的一種具體方案 思路分析 昨天打了一天的Dinic&#xff0c;今天又打了…

機器學習實踐六---K-means聚類算法 和 主成分分析(PCA)

在這次練習中將實現K-means 聚類算法并應用它壓縮圖片&#xff0c;第二部分&#xff0c;將使用主成分分析算法去找到一個臉部圖片的低維描述。 K-means Clustering Implementing K-means K-means算法是一種自動將相似的數據樣本聚在一起的方法,K-means背后的直觀是一個迭代過…

航海家軟件公式全破解

水手突破 上趨勢:MA(LOW,20)*1.2,color0080ff,linethick2;次上趨勢:MA(LOW,20)*1.1,COLORYELLOW;次下趨勢:MA(HIGH,20)*0.9,COLORWHITE;下趨勢:MA(HIGH,20)*0.8,COLORGREEN,linethick2;ZD:(C-REF(C,1))/REF(C,1)*100;HDZF:(HHV(H,20)-C)/(HHV(H,20)-LLV(L,20));趨勢強度:IF(C&g…

打包 壓縮 命令tar zip

2019獨角獸企業重金招聘Python工程師標準>>> 打包 壓縮 命令tar zip tar語法 #壓縮 tar -czvf ***.tar.gz tar -cjvf ***.tar.bz2 #解壓縮 tar -xzvf ***.tar.gz tar -xjvf ***.tar.bz2 tar [主選項輔選項] 文件或目錄 主選項是必須要有的&#xff0c;它告訴tar要做…

mysql免安裝5.7.17_mysql免安裝5.7.17數據庫配置

首先要有 mysql-5.7.10-winx64環境: mysql-5.7.10-winx64 win10(64位)配置環境變量&#xff1a;1、把mysql-5.7.10-winx64放到D盤&#xff0c;進入D\mysql-5.7.10-winx64\bin目錄&#xff0c;復制路徑&#xff0c;配置環境變量&#xff0c;在path后面添加D\mysql-5.7.10-winx6…

tidb數據庫_異構數據庫復制到TiDB

tidb數據庫This article is based on a talk given by Tianshuang Qin at TiDB DevCon 2020.本文基于Tianshuang Qin在 TiDB DevCon 2020 上的演講 。 When we convert from a standalone system to a distributed one, one of the challenges is migrating the database. We’…

機器學習實踐七----異常檢測和推薦系統

Anomaly detection 異常檢測是機器學習中比較常見的應用&#xff0c;它主要用于非監督學習問題&#xff0c;從某些角度看&#xff0c; 它又類似于一些監督學習問題。 什么是異常檢測&#xff1f;來看幾個例子&#xff1a; 例1. 假設是飛機引擎制造商&#xff0c; 要對引擎進行…

CODE[VS] 1621 混合牛奶 USACO

題目描述 Description牛奶包裝是一個如此低利潤的生意,所以盡可能低的控制初級產品(牛奶)的價格變的十分重要.請幫助快樂的牛奶制造者(Merry Milk Makers)以可能的最廉價的方式取得他們所需的牛奶.快樂的牛奶制造公司從一些農民那購買牛奶,每個農民賣給牛奶制造公司的價格不一定…

apply和call用法

apply語法 func.apply(name, [array])第一個參數指定函數體內this對象的指向&#xff0e;第二個參數為一個帶下標的集合&#xff0c;可以是數組或類數組,apply方法把這個集合中的元素作為參數傳遞給被調用的函數var func function(a, b, c) {console.log([a, b, c]); // [1,2,…